The == (double equals) returns true, if the variable reference points to the same object in memory. This is called “shallow comparison”.

The equals() method calls the user implemented equals() method, which compares the object attribute values. The equals() method provides “deep comparison” by checking if two objects are logically equal as opposed to the shallow comparison provided by the operator ==.

If equals() method does not exist in a user supplied class then the inherited Object class’s equals() method will be called which evaluates if the references point to the same object in memory. In this case, the object.equals() works just like the “==” operator.

Also “deep” and “shallow” are used to refer to copying, not comparison. But by analogy, “deep” comparison would mean comparing two objects, and all the objects they reference as members, and all the objects they reference, etc. “Shallow” comparison, in contrast, would mean just comparing two objects.