How To Call Java Methods From Different Java File
Apr 14, 2015
I create 2 files:
CircleCalculationMethod.javaMain.java
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...
I use Eclipse software
View Replies
ADVERTISEMENT
Mar 25, 2015
I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:
import javax.swing.*;
import java.awt.*;
public class BelishaBeacon {
public void BeaconFrame() {
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();
[code]....
View Replies
View Related
Aug 6, 2014
I have a question about a method I have. In my game, I had a move method to move my player left and right, and originally this method was huge, as it also took care checking collisions and a few other things. I broke it up a bit and put the collisions in their own methods and call them from again another method... Here is an extract which I hope illustrates my point:
private static final double MOVE_SPEED = 0.2;
private static final double MAX_MOVE_SPEED = 3.5;
private static final double STOP_SPEED = 0.18;
private double xPos;
private double yPos;
[Code] .....
Something I thought might be a good idea is to check the direction collision when im doing the calculations for that direction:
if(moveLeft) {
dx -= MOVE_SPEED;
(dx < -MAX_MOVE_SPEED) {
dx = -MAX_MOVE_SPEED;
}
checkLeft();
}
But then I would also need to check it when I'm slowing down the left movement:
if(dx < 0.0) {
dx += STOP_SPEED;
if(dx > 0.0) {
dx = 0.0;
}
checkLeft();
}
Then I thought instead i can check it after both of these steps:
if(moveLeft || dx < 0.0) {
checkLeft();
}
I guess my question is quite general: How much is acceptable to break up a method? How many chains of method calls is acceptable? Is it ok to call the same method from different nearby places?
View Replies
View Related
Apr 14, 2014
I have a EAR file which has a java class file and EAR file is deployed in weblogic.I have to call the java class of EAR file from a standalone java code which is present inside a JAR.While making the call to EAR i have to pass a parameter from JAR to one of the methods of class file which is present in EAR.
View Replies
View Related
Dec 23, 2013
I am newbie in java and little bit known to apex. I write an java code and compile it to class file. Now i want to call that class file from an push of button on apex. When button is pushed i need some arguments to be password to java class files . For arguments i need to take the item value from the apex page.
But i stuck on how to call that java class file from apex. On command prompt when i ran java class file, its working.
View Replies
View Related
Jul 21, 2014
whether we can call DTS directly from Java.Solution which we got as below:-
1. Create dts
2. Create job in which we have to call dts
3. Call job from stored procedure
It pretty lengthy process and we are not sure how error handling can be done in this scenario.
View Replies
View Related
Jul 22, 2014
We are using MS SQL server 2000, in which we have explored calling dtsrun.exe from Runtime class in java. But it is not suggested way to call dts, as error handling will be difficult.
whether we can call DTS directly from Java.
View Replies
View Related
Apr 16, 2015
how come you can call non static methods from other classes(objects when they are created from main) but not static methods in the same class as the main method??
example I cannot call the method maximum from the main method aslong as its not static BUT i can call other objects non static methods from main??
class test{
public static void main(String [] args){
Scanner input = new Scanner(System.in); //create new Scanner object
//for input
int number1;
int number2;
[Code]...
View Replies
View Related
Apr 28, 2014
I am trying to call a java method in jsp. The main idea is to hide menu based on the user who logs in. The java class flows like this :
public class UserVerification {
public static void main(String[] args) {
UserVerification obj = new UserVerification();
System.out.print(obj.GetUserVerification("abc"));
[Code] ......
View Replies
View Related
Jun 2, 2014
If I had this code:
<h:dataTable value="#{customer.customerList}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
And in the server getCustomerList() accessed to database, how many times getCustomerList() would be called from I request the xhtml page?. I have read this would be called several times because of JSF internals and It would be better to store it in a variable and access this variable.
1. Is this true this would be called several times? why?
2. If the previous statement was true, how to avoid it, I mean not call the method from a service?
View Replies
View Related
Apr 17, 2014
Life Cycle Call back methods(init(), destroy(),...) are not transactional by default and expecting this in coming EJB releases (EJB 3.x / EJB 4.x). I was expecting next EJB release along with Java 8, but it stays at 3.2
View Replies
View Related
Mar 4, 2014
I used java and jsf. I created dynamic datatable in java file. Can i call java method from setOnchange() event?
I am able to call java script function from setOnchange() event. See the below code which is working fine for java script.
HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
selectOneMenu.setStyleClass("dropdownStyleTwo");
selectOneMenu.setOnchange("openWin(this);IGNORE_UN LOAD=false");
I wrote openwin() function in java script. But i am not able to call java method change().
Code which is not working.
HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
selectOneMenu.setStyleClass("dropdownStyleTwo");
selectOneMenu.setOnchange("myclass.change();IGNORE _UNLOAD=false");
myclass is the bean of class Test. If user select any value from dropdown i want to call change java method. This function will apply the same selected dropdown value to the other record also.
View Replies
View Related
Feb 18, 2014
I am new to Java and have been learning it. I have a question here. I came across the following Java class and trying to understand it thoroughly but got confused how it is able to call an abstract method. Here is the code I am referring to :
package sampleapps.gui;
import javax.swing.*;
import java.awt.*;
public class InnerClassAnimationExample {
int x=70, y=70;
public static void main(String[] args) {
[Code] ....
So, in the code above, there is an inner class NewMyDrawPanel which has a paintComponent(Graphics g) method. I have highlighted 2 lines of code above.
Line 1 : Graphics2D g2d = (Graphics2D) g;
Line 2 : g2d.fillOval(x,y,40,40);
I understand we are type casting reference g to Graphics2D reference g2d and we are calling fillOval() method on g2d. I don't see a fillOval() method in Graphics2D class but it is there in Graphics class and fillOval method is an abstract method.
So, my question here is :
1. If we are not able to instantiate an abstract class(Graphics2D and Graphics classes), how are we able to access the fillOval() abstract method,
2. Secondly, since the fillOval() method is an abstract method, it does not have any implementation for the method.
However, when I call the method fillOval() on Graphics2D reference, I was able to draw and fill an oval of the specified co-ordinates. So, where would the actual implementation code be?
View Replies
View Related
Jun 12, 2014
I have to call a java method using only varags in its prototype :
public void _instanceMethod(Object... obj) {
....
}
that is equivalent to :
public void _instanceMethod(Object obj1, Object obj1, ..., Object objn) {
....
}
My question is simple : I only own a List<Object>How can I set each element of _instanceMethod parameter from my List ?? If i decided to iterate through my list such as :
for (Object obj : myList){
_instanceMethod(obj);
}
How can I correctly "populate" the _instanceMethod varargs signaturee by the n elements of my list ?
View Replies
View Related
Aug 18, 2014
I am having problems in creating an age calculator in java. The only input is your name and date of birth. It means I need to incorporate the current date and make conditions. I am only allowed to use BufferedReader, InputStreamReader and IOException for import. I need to start with this and just add the conditions,
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
public class ageactivity
{
public static void main (String[] args) throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
[code]...
I tried to add conditions but its not calculating the days.
View Replies
View Related
Feb 5, 2014
We are in the process of developing a e-commerce application. It is a web site for a book shop. It is a site very similar to Amazon.com where you can order books online. Front end is in Java Technology. There is however a concern about where to put the business logic.
I am suggesting to put all business logic in the Oracle Database, as stored procedures (i.e. packages). However, one of my colleague says that when you call a Oracle stored procedure from Java, it takes 2 round trips, one to validate the procedure and then to validate the input / ouput parameters of the procedure.
In a website application like what we are trying to build, is it sound advice to put all business logic in the DB? Or should it be in the middle tier (app. server) programmed in Java? Or should you spread in between the middle tier and DB? If so how?
View Replies
View Related
Mar 23, 2015
I'm new to Java. I need to run a SQL server stored procedure(that creates a unique job number) from Oracle SQL Developer (JDBC) in Java. The same Java code will be used in Applescript to run the SP. I found a code snippet online with the similar requirement. How to embed my SP in below code snippet? Below is the Stored Procedure and Code Snippet:
SP
EXEC Int.dbo.GetNewJobNumber '6852', 'Test Job', 'Manual SQL Query'
6852- CustomerCode,
Test Job - Job Title,
Manual SQL query - Shows how new job number was created.
Code Snippet:
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Main {
public static void main(String[] argv) throws Exception {
[Code] ....
View Replies
View Related
Dec 19, 2014
For reference I am programming Java in BlueJ. I am fairly new to the language and I am having trouble with sorting.
I am trying to call / test all of the 5 sorting methods (at the same time) in the main class. To be specific, the sorted list has to technically outputted 5 times.
I figured out how to call / test Quicksort:
Sorting.quickSort(friends, 0, friends.length-1);
But the others are not working correctly. Specifically these:
Sorting.mergeSort(friends, 0, friends.length-1);
Sorting.PbubbleSort(friends, 0, friends.length-1);
Sorting.PinsertionSort(friends, 0, friends.length-1);
Sorting.selectionSort(friends, 0, friends.length-1);
For reference, this is the output when it is not sorted:
Smith, John 610-555-7384
Barnes, Sarah215-555-3827
Riley, Mark 733-555-2969
Getz, Laura 663-555-3984
Smith, Larry464-555-3489
Phelps, Frank322-555-2284
Grant, Marsha243-555-2837
This is the output when it is sorted:
Barnes, Sarah215-555-3827
Getz, Laura 663-555-3984
Grant, Marsha243-555-2837
Phelps, Frank322-555-2284
Riley, Mark 733-555-2969
Smith, John 610-555-7384
Smith, Larry464-555-3489
This is the class Sorting, which I should note is all correct:
public class Sorting{
/**
* Swaps to elements in an array. Used by various sorting algorithms.
*
* @param data the array in which the elements are swapped
* @param index1 the index of the first element to be swapped
* @param index2 the index of the second element to be swapped
*/
private static <T extends Comparable<? super T>> void swap(T[] data,
int index1, int index2){
T temp = data[index1];
data[index1] = data[index2];
[Code]...
This is the Main class in which I am supposed to call the sorting methods, SortPhoneList:
public class SortPhoneList{
/**
* Creates an array of Contact objects, sorts them, then prints
* them.
*/
public static void main (String[] args){
Contact[] friends = new Contact[7];
friends[0] = new Contact ("John", "Smith", "610-555-7384");
friends[1] = new Contact ("Sarah", "Barnes", "215-555-3827");
[Code]...
View Replies
View Related
Feb 14, 2015
I'm new to Java, and I just created this script:
public class HelloWorld {
public static void main(String[] args) {
String firstLine;
String startUp;
int hour, minute;
[code]...
Every time I try to run this is eclipse, I only get the first part, so it reads in the console: "Hello, world. The time is now 9:15. I'm tired."I want it to read: "Hello, world. The time is now 9:15. I'm tired. (new line) Today is Wednesday."
View Replies
View Related
Aug 6, 2014
I have a 'small' question:I am trying to create a method that will deduct the same percentage for a number of times, example:
a + b = c
c - 3% = d
d - 3% = e
e - 3% = f......
and so on and so forth, for a number specified earlier in the program, until I get to my final result.
View Replies
View Related
Jun 16, 2010
Why can't we have static methods in an interface?
View Replies
View Related
Jun 3, 2014
I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but is sth wrong with it
public class Stiva {
/** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/
int Gjmax;
int array[] = new int[Gjmax];
int kreu;
private Stiva stiva1;
private Stiva stiva2;
[Code] .....
View Replies
View Related
Aug 6, 2014
How to build an array that calls methods if i understand it correctly .... if this is possible a simple example of this.
View Replies
View Related
Jun 3, 2014
I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but something wrong with it....
public class Stiva {
/** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/
int Gjmax;
int array[] = new int[Gjmax];
int kreu;
private Stiva stiva1;
private Stiva stiva2;
[Code] .....
View Replies
View Related
Apr 4, 2014
1. Modify the following class so that the two instance variables are private, there is a constructor that accepts both the player's name and sport and there are get and a set methods for each instance variable:
public class Player {
String name;
String sport;
}
2. You can pass an instance of this class to the JLabel constructor if you want to display text in the label.Select one:
a. myLabel
b. myText
c. String
d. JTextField
e. JLabelText
how to start making this work?cause i am not familiar with the terms here and want to complete this program and I am new to java programming?
View Replies
View Related
Apr 1, 2015
Consider the two simple Java classes below:
Java Code:
class Computer {
Computer() {
System.out.println("Constructor of Computer class.");
}
void On() {
System.out.println("PC turning on...");
}
void working() {
[Code] ....
After the program run, how do I trace (1) which object call which method (2) and how many times?
View Replies
View Related