aspose 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1050

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: 9280
    
  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
 
Consider Paul's rocket mass heater.
 
subject: what is the difference between == and .equals() method????
 
Similar Threads
Differnce between == and equals
Difference between '==' & equals()
== and .equals()
difference between equals() and == and compareTo()
equals() and hashCode()