There is a "contract" that objects being equals() -> true must have the same hash code value. However two objects having the same hash code value are not obligatorily equals() -> true. Default implementations of equals() and hashCsode() compares memory adresses not field values of your object and that is what you want if you Let's say you override equals() by using fields of your object a business model object. If equals() is overridden in a manner that it checks object fields for equality but hashCode() still has the default implementation youmight face trouble storing and retreivig objects in a HashMap. Let's say you put a Person in a HashMap. The name variable's value is "John". If you look for a person named John in your HashMap it will look for the hash value first. If the value is not found it returns a NULL value hence it doesen't work correctly. If you override both method the shoulb be overridden correctly. If your hashCode() alsways returns an int=9 it is worth nothing.
a.equals(b)=>Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses
Comparable interface. Compares values and returns an int which tells if the values compare less than, equal, or greater than. If your class objects have a natural order, implement the Comparable interface and define this method.
Consistency between results from equals and results delivered by compareTo is highly recommanded, but not necessary, except if you are using sorted maps.
The interface SortedMap implements the interface Map. Map is defined using the operation equal for comparission and SortedMap is defined using compareTo. Please see the Oracle documentation for SortedMap: http://docs.oracle.com/javase/7/docs/api/java/util/SortedMap.html