My first suggestion would be to have look at this topic in K&B book, this is discussed in details overe there.
However, I will try to give you brief idea of hashCode() function.
The rule for hashcode and equal is
"Equal objects must produce the same hash code as long as they are equal, however unequal objects need not produce distinct hash codes."
One of the place I can see this happening is HashMap class in Java API, Lets say you have a Student class and you override equals() method in this method you have logic to determine how two student object from your Student class can be equal. You also override hashCode() and return a constant lets say any number say "8".
Now imagine in you application you have some informtaion per student object and you are storing this information in a hashmap cache where student object is being used as key and some other object being used as value in hashmap.
When you call get() method on hashMap, you need to pass the key in this case it would be object of Student class. On high level Hash Map does following to get the mapping of key on invocation of get(). 1. It will call hashCode() method of the Key object to find the hash address of the key in Map.
2. Once the hash adress is located it will check all the key objects stored in that hash bucket using equals() method and the object whose equals() method return true will be return.
Therefore if in your application lets say you are adding Student objects in cache using hashMap at startup and then that map outlived the code which populated that hashmap now to read back those objects from map you need to make sure that if two objects in your Student class are equal they are having same hashcode, otherwise you might not able to get the data from hashMap even if its exists in map.
[ March 10, 2008: Message edited by: yogesh sood ]