Possible Duplicate:
what is an objects hashcode
Let’s say that I create an object, called Employee which has id, firstName, lastName and email for instance variables and corresponding setter/getter methods. How is hashCode() calculated if I don’t override hashCode() in Employee object when it is stored in collection objects?
If you don’t override hashcode() then the default implementation in Object class will be used by collections. This implementation gives different values for different objects, even if they are equal according to the equals() method.
Some collections, like HashSet, HashMap or HashTable use the hash code to store its data and to retrieve it. If you don’t implement hashcode() and equals() in a consistent manner, then they will not function properly.
Edit:
As per Javadoc: Object.hashcode() is ”typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java(TM) programming language”. Therefore I would advise not to rely on a specific implementation. For what the implementations really do, see this answer to a similar question.