System.out.println("int i is: " +i);
System.out.println("int j is: " +j);
j=i;
System.out.println("int j is: " +j);
Does the code j=i mean that the value of i is passed into j or the reference?
I'm always confused with pass by reference and value.
What is want to do is to pass the value 5 into j, yet when i code j==i and compile it, it says the line is not a statement. Can't compile..
07-31-2005, 11:10 AM
sjalle
The value. Reference is for objects, ints are not objects.
j==i is not a statement its a boolean.
07-31-2005, 02:50 PM
Ant_Magma
So == is only applicable when used with objects and boolean. With objects it is passed by reference, meaning both pointers would b actually pointing2 the same object..correct?
08-01-2005, 01:09 AM
sjalle
== can be used for both object and non-oblects (int, double, float, boolean, char &
reference comparison).
j==i is a boolean expression. For comparing objects content java uses the
equals(Object ob) method as this language does not offer operator overloading.
The answer is yes, == used for objects will be true if the references are for the same
memory location.
08-01-2005, 01:28 AM
Ant_Magma
how is j==i a boolean expression? j and i are already both declared as int, how is it boolean?
08-02-2005, 09:24 PM
deroga
j==i is boolean in the sense of:
if (j==i){ do stuff }
if j = 5 and i = 4 then do stuff would not happen
if j = 5 and i = 5 then do stuff would happen.
08-03-2005, 02:54 AM
Phaelax
use "=" to assign a value to a variable. Use "==" when comparing two values.
j==i is saying that "does j equal i". The expression will either return TRUE or FALSE;