File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes == and equals() 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 » Java » Beginning Java
Bookmark "== and equals()" Watch "== and equals()" New topic

== and equals()

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Kindly explain what (& why) is going behind the scenes in the following program,

Output is

different objects
meaningfully equal
same object
meaningfully equal


Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Please search the forums, there have been discussions on this topic before, infact with the same numbers.
marc weber

Joined: Aug 31, 2004
Posts: 11343

As Sridhar suggested, you will find this discussed by searching the forums.

The technical specification is under JLS - 5.1.7 Boxing Conversion...
If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: == and equals()
It's not a secret anymore!