Package, Class and Interface

1. Always use explicit import statements

Avoid using the wildcard import statement. Instead list all classes in the import statement. Explicit import statement help maintainer of the code to understand the precise list of dependency of the code. This makes it easier to understand how dependent a class is on other classes (the higher dependency, the more complex the class).

consistent: x.equals( y ) should stay constant if no changes are made to x and y for all non-null objects x and y

3. Define both equals(Object o) and hashCode()

If you define equals(Object o) then you must define hashcode() and vice versa.

The following property should be satisfied when defining these two methods. For two given objects o1 and o2 o1.equals(o2) implies o1.hashCode() == o2.hashCode()

Similarly, if compareTo(Object o) is overridden, then also equals(Object o) (and consequently hashCode()) should be. That is, the following contract should be satisfied:o1.compareTo(o2) == 0 if and only if o1.equals(o2)