File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Dan's exam. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Dan Watch "Question from Dan New topic

Question from Dan's exam.

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
This is a simple question from Dan's exam.
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
Boolean b3 = new Boolean("TrUe");
Boolean b4 = new Boolean("tRuE");
System.out.print((b1==b2) + ","); //1
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");//2
Ths ans given is : false,true,true
My doubt is in the line #2. It seems to be v..simple but i am getting confused. When ohjects are not equal(line #1), how can the value be the equal in (line#2) .
Pl. explain this.
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
Hi There,
It is simple
In line#1 u r comparing the objects themselves , since they r stored at diff. locations in memory it returns false , while in lines 2 and 3 you are comparing the values stored at these memory locations which returns true.
Hope it makes sense,
Good luck;

"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
I agree. Here's the link:
subject: Question from Dan's exam.
It's not a secret anymore!