my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes jxam == question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "jxam == question" Watch "jxam == question" New topic
Author

jxam == question

Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
Here you go heroes:
int x = 10;
float f = 10.0f;
x==f;
explanation:
x will be promoted to a float for the comparison and they will be the same value when that occurs.
Is this right?
I thought == meant "the same space in memory".
Thanks for clarifying.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
you must distinguish between primitive and reference type. == compares the space in memory for reference types and the value for primitive types.
int a=0,b=3;
a==b; // the value of a and b are compared for equality
Object o1=new Object();
Object o2=new Object();
o1==o2; // the references of o1 and o2 are compared for equality, in this case the test fails because we have 2 different objects
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
If you read any of the books on comparison you will see that in any comparison of numeric values the smaller data type will be automatically be promoted to the larger before the comparison. Also you said "I thought == meant "the same space in memory" ....NOT for primitives, that is for objects.
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
Thanks for the clarification. So... there are books on comparison huh?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jxam == question
 
Similar Threads
final variable
Kindly help me in Java.lang.float problems
primitive types
primitive types
float variable