Tuesday, 10 May 2011

What are the different methods of identifying an object?

There are three methods by which an object can be identified.
  1. Object identity – Objects are identical if they reside in the same memory location in the JVM. This can be checked by using the = = operator.
  2. Object equality – Objects are equal if they have the same value, as defined by the equals( ) method. Classes that don’t explicitly override this method inherit the implementation defined by java.lang.Object, which compares object identity.
  3. Database identity – Objects stored in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key value.

No comments:

Post a Comment