public static void f() { int n = 5; p(n, 2 * n); } public static void p(int a, int b) { int x = 1; q(x, a + b); } public static void q(int x, int y) { int z = x + y; x = 0; ... } mh_sh_highlight_all('java');
When we write x = 0; that refers to the formal parameter int x and hence it's the formal parameter that changes value. why isn't the value of the actual parameter also changing?
I have a question about query execution strategy ...
Scenario: let's suppose I've to query a table with a query like
SELECT F1, F2, F3 FROM MYTABLE WHERE F1 = ? AND F2 = ? AND F3 = ?.
I need to execute this query changing parameters' actual values in a combinatorial way, until a combination gives back at least one row or all combinations are unsuccessfully tried. For instance, I may have this sequence of values:
(V1,V2,V3); (V1,V2,""); (V1,"",V3); (V1,"","");
where V1, V2, V3 may by string values and V1 is always present, not null, and not blank in each combination.
A first strategy may be to prepare the statement, clear the parameters each time I execute the query, until stop condition is met.
I wonder if may be more efficient transform the query into
SELECT F1, F2, F3 FROM MYTABLE WHERE F1 = V1
and cycling over the cursor and, for each cursor row, verify if the returned tuple (F1,F2,F3) matches the combination (V1x,V2x,V3x). When at least 1 rows matches, or all combination are done, I'll exit iteration.
I wrote a Chess game that uses socket to connect to another computer, and allow player vs player and player vs computer game sessions.
However, there is a problem which I noticed.
When you get the IP address of the computer in which the program is running, you are not getting the computer's actual IP, you are getting the Router's IP.
Is there a way to get around this.
So the problem is that when I go to another computer, located in a different house or lets say from my school, the program cannot connect back to my home IP, because it uses the router's ip, not the computer's ip I am running the server program.
Is there a way to get the Computer's IP, not the router's ip when summoning or invoking the get IP address method from the socket class?
When I say that the socket class is acquiring the router's ip, well that's done without my interfering...I don't know why it does that, it is somehow recognizing the router and not the computer.
The thing is that the server program is written that any client program is able to connect to the home server.
But when I run the program from a different location other than the current home, the sockets don't connect because it is somehow recognizing the router's ip not the computer's ip.
I have an applet that uses JPanels to draw images in. I want to include actual jpgs now instead. The applet points to a .jar file. I want to use any number of images here, do I have to include them all in the jar file or is there another way to "point" to them (like html)?
Now lets say that I want to access a method 'addInterest()' that is in the 'SavingsAccount' class I would have to do: '((SavingsAccount)s).addInterest();'
The question I have is why do I have to cast 'b' to SavingsAccount? Isn't the actual object reference of 'b' already an instance of 'SavingsAccount' class? How does the 'BankAccount' affect the object itself? I'm really confused as to what class is truly getting instantiated and how BankAccount and SavingsAccount are both functioning to make the object 'b'.
I can understand result 3 is because of an upcast from short to int, since FunWithOverloading will not have a overloaded method with short now. However, what is happening with result 4? Shouldn't it call methodA of the subclass with the argument type short? If its because I have declared the reference variable, derived, of the type FunWithOverloading, then how come the first result correctly picks the overloaded method of the sub class?
class FunWithOverloading{ void methodA(int x){System.out.println("Integer method " + x);} void methodA(short x){System.out.println("Short method " + x);} //line 3 } class OverloadedSubClass extends FunWithOverloading{ void methodA(short x){System.out.println("Sub class short method " + x);}
how objects relate to classes and how you can create and re-use object types.on that point, but this has me baffled. I most certainly do not have a firm grasp yet on passing things to and from methods that just makes my head hurt. SO anyway I tried out one of the code examples:
/* ElectricGuitar.java */ class ElectricGuitar { String brand; int numOfPickups; boolean rockStarUsesIt;
[code]...
But I just realized this thing has no main method and only one class defined.....so I guess I just tried to compile.
I am trying to understand the concept of Generics in java. In the introduction to Generic Types, this example is given:
Java Code: public class Box { private Object object; public void set(Object object) { this.object = object; } public Object get() { return object; } } mh_sh_highlight_all('java'); "Since
Since its methods accept or return an Object, you are free to pass in whatever you want, provided that it is not one of the primitive types." - I understand this.But then it has been changed to a generic class:
Java Code: /** * Generic version of the Box class. * @param <T> the type of the value being boxed */ public class Box<T> { // T stands for "Type" private T t;
public void set(T t) { this.t = t; } public T get() { return t; } } mh_sh_highlight_all('java'); "
As you can see, all occurrences of Object are replaced by T. A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable."We can use any type in place of an Object, because Object is a superclass of all classes. But T (or any other class) is not a superclass of all classes. So how do we justify any class being used in place of a random T or any other class?
public class AutoBoxingExample { public void add(Integer intVal){ System.out.println("Wrapper"); } public void add(int value){ System.out.println("Primitive"); } public static void main(String[] args) { AutoBoxingExample auto = new AutoBoxingExample(); auto.add(12); } }
The output is "Wrapper". What would be the reason behind it?
GoodEmployee is defined who has ALL the following properties:
He should be married. He should have 2 or less than 2 children. His middle name should start with "k" but not end with "e" The last name should have more than 4 characters The character "a" should appear in the last name at least two times. The name of one of his children should be "Raja"
isMarried true if the employee is married. noOfChild the number of children of the employee. middleName the middle name of the employee lastName the last name of the employee. childNames the array of the names of the children of the employee
So I created this line class and when I try to create Line object with parameters, I don't know how to pass the parameters properly. It has to return two points, so it should be like [(1,2),(5,12)].I tried different things likeLine l1=new Line(Point p1(1,2),Point p2(5,12)); and similar, but nothing worked.
package line; import java.awt.Point; public class Line { private Point p1; private Point p2;
public class TestClass { public TestClass(String k){System.out.println(k);} public static void main(String[] args) { try { hello(); } catch(Exception e){System.out.println(e);}
[Code] ....
Explain how to catch block act as constructor with parameter?
I have this JAVA written but I can't get the parameters for the if statements right.
import java.util.Scanner; public class myFirstJAVA { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter command: "); String text = input.nextLine();
import javax.swing.JOptionPane; public class Input { public static void main(String[] args) { int user; user = JOptionPane.showMessageDialog(null, "Enter Your Age""); ERROR IS HERE if(user <= 18) { JOptionPane.showMessageDialog(null, "User is legit"); } else { JOptionPane.showMessageDialog(null, "User is not legit"); } } }
I'm getting this error message :
incompatible types: void cannot be converted to int
I need to write a class that represents and image of RGB pixels. This class uses a two-dimensional array of object type that represents R,G and B values.
When I compile the class it completes successfully. However, when I try running a "tester" class , I'm encountering errors in a few methods. I've been trying it out for 2 days now, but unsuccessfully thus far..Those method are : rotating the image by 90 degrees clockwise (and vice versa , but I just use clockwise method 3 times for that) , shifting the image sideways, and shifting the image up/down..
I've attached the whole source code for the class , and the list of errors I get when I try to run my tester. URL...
I am looking at a snippet of code in my "learning Java 4th edition" by Orielly and there is a small snipped of code which says:
Java Code: Date date = new Date(); List list = new ArrayList(); list.add( date ); ..
Date firstElement = (Date)list.get(0); // Is the cast correct? Maybe. mh_sh_highlight_all('java'); so I am typing the same thing in my compiler in a small Driver class and for some reason I have an error and Im dumbfounded...