Please go through this following link. Hope this will help you. http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html
CompareTo() method in Java must be compatible with equals method in Java i.e. if two objects are equal via equals method compareTo method must return “0″ for them, failing this may result in some subtle bug when you store those objects in collection class like arraylist in java. For detailed answer check here http://javarevisited.blogspot.in/2011/02/how-to-write-equals-method-in-java.html
Give proper explanation.
I am new in Java but I have knowledge about C programming.
Why do I need to override the equals and hashCode methods in Java? I mean Why always override hashcode() if overriding equals()?