Rajesh Khan wrote:I read that == is tells us whether the two objects point to the same address
Not quite. The == operator tells us whether two reference values are equal. That is, whether two references point to the same object, or both are null. Objects don't point to anything. References point to objects.
and .equal checks the contents of the address rite ??
The equals() method does whatever the author of the class wants it to, but the correct behavior is to compare fields ("contents") for equality, so that if two distinct objects have the same values in the appropriate fields (as per that class's semantics), then they are considered equal.
If you don't override equals(), you inherit it from Object (or from whichever ancestor did override it.) Object's equals() just does ==.