File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the difference between == and .equals() method???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the difference between == and .equals() method????" Watch "what is the difference between == and .equals() method????" New topic
Author

what is the difference between == and .equals() method????

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

what is the difference between == and .equals()method


http://www.lifesbizzare.blogspot.com || OCJP:81%
Snehal Bachchhav
Greenhorn

Joined: Nov 23, 2009
Posts: 4
Hi..............

=-= Method checks wether two objects refer to same class
whereas equals method actually check values between two objects......................
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

Snehal Bachchhav wrote:
=-= Method checks wether two objects refer to same class


== used to check two reference variables refers to same object

regards,
Anbarasu


A.A.Anbarasu
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

As everyone said, == is used to check if two references point to the same object. equals is used for meaningful comparison of objects. If you create a custom class (lets say employee class), then you can override the equals method to provide a meaningful comparison of objects (like check if empId is equal for two objects). The default implementation of equals method in Object class does a direct == comparison so is equivalent to using == operator (ignoring incompatible objects which cannot be compared) unless it is overridden...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the difference between == and .equals() method????
 
Similar Threads
== and .equals()
Difference between '==' & equals()
difference between equals() and == and compareTo()
equals() and hashCode()
Differnce between == and equals