The complicated contracts that go with these methods make overriding them correctly very difficult. Some of the code shipped with the standard Java libraries gets it wrong. It need not return the same value for different runs of an application or applet. If two objects are equal according to the equals method, they must return the same value from hashCode . The equals method is consistent.
Object provides a simple implementation of equals .
The equals implementation of java.lang.String , for example, returns true if the two objects are both String objects containing exactly the same characters in exactly the same order. The equals method of java.awt.Dimension returns true if the passed-in object is a dimension with the same width and height as the Dimension object executing the equals method. The default implementation of hashCode provided by Object returns something corresponding to the object's address in memory or location in the Java virtual machine's global object array. Again, some of the standard Java classes override this method. String , for example, overrides the hashCode implementation in Object to return a hash of some or all of the characters making up the String .