This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by Niranjan Prasad: Why hashCode() must be overriden when equals() is overriden?
Because they both go hand-in-hand to determine the unique identity of an object. By definition, every object that is unique has a unique hash code, and every two objects that are equal have the same hash code.
Thus, if you are implementing your own way of testing equality, this consistency must still be maintained, for which you must also implement the hashCode() based on your specific logic for that class, such that the above requirements still hold.