Overriding equals and hashcode is useful in the cases when you want to check the equality of objects based on some field of the object.
for ex.
class Book{
int bookId ;
Book(int id){bookId = id;}
}
Book b1 = new Book(1);
Book b2 = new Book(1);
now if you try b1 == b2 you will get false because b1 and b2 refering to two different instances. so if you want to make two instances of book equal in case bookId is equal then you have to override equals.
then b1.equals(b2) will be true. now according to equal contract if two objects are equal then their hashcode must be equal. so if you are overriding equal
you should override hashcode as well.