With identity i mean the identity of the object with respect to heap and that can be easily found using the hashcode.In case the hashcode of the considered object is overriden then you can go for identityHashCode method in the System class to get the actual identity of the ocject.

Rahul, I don't you why you suddenly start talking about hash codes, but you cannot use Object.hashCode() or System.identityHashCode(...) to check if two objects are equal.

Sure, if two objects are equal then they will have the same hash code, but two different objects may also have the same hash code. Hash codes only work "in one direction", not in both directions. The hash code of an object does not represent the unique identity of an object.

Read the API documentation of Object.hashCode() for information on how hash codes work in Java. [ October 18, 2006: Message edited by: Jesper Young ]

Originally posted by Jesper Young: Rahul, I don't you why you suddenly start talking about hash codes, but you cannot use Object.hashCode() or System.identityHashCode(...) to check if two objects are equal.

Sure, if two objects are equal then they will have the same hash code, but two different objects may also have the same hash code. Hash codes only work "in one direction", not in both directions. The hash code of an object does not represent the unique identity of an object.

Read the API documentation of Object.hashCode() for information on how hash codes work in Java.

[ October 18, 2006: Message edited by: Jesper Young ]

Its true like what you have explained about equals and hashcode of an object.I was trying to explain the literal meaning of identity of an object with respect ot its location in the heap. That is all. Thanks,