This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regarding scjp 1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regarding scjp 1.5" Watch "regarding scjp 1.5" New topic

regarding scjp 1.5

anveshana bandu
Ranch Hand

Joined: Oct 09, 2007
Posts: 42

Please explain this...........very urgent....

1. public class EqualsTest{
2. public static void main(String args[]){
3. Long L = new Long( 7 );
4. Integer J = new Integer( 7 ) ;
5. if( L.equals( J )) System.out.println("Equal");
6. else System.out.println("Not Equal");
7. }
8. }

The out put is "Not Equal".....How???
Content is equal............
I did not understood how equals method checks whether two objects are equal...
Please explain how equals() method works....
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Because their classes are different (a Long is NOT an Integer).

SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15042

Anveshana: Please quote your sources.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
srk bhushan

Joined: Oct 26, 2007
Posts: 3
Here the two classes are different, you cant compare to class objects with equals method. If you want you have to overload the equals method in your class. Using equals method you can compare primitive and reference variable's equality but not objects.
venkat kaka

Joined: Sep 27, 2007
Posts: 10
equals method works on the data of the objects if both object are of the same class.
anveshana bandu
Ranch Hand

Joined: Oct 09, 2007
Posts: 42
Thank you very much to you all for giving reply to my doubt...
Don't get me started about those stupid light bulbs.
subject: regarding scjp 1.5
It's not a secret anymore!