Java in the eyes of a C++ developer (IV)– Object Class

In java, all aggregate data types and arrays are derived from the ancestor class Object. The Object class provides common functionality desirable for an aggregate datum or an array in a computing environment.

  • Monitor Lock

An Object instance maintains an intrinsic lock which can be used in conjunction of synchronized keyword in multi-access context to guarantee exclusive access to the critical section as shown below.

public void do() {
  synchronized(this) {
     .../* critical section */
}

}

  •  Runtime class  type tracking

The generic Class instance of a class/interface provides an inside view of the aggregate date type.  A program may obtain the Class object for an Object and its subclass instance, with which, precise information about the fields, constructor, annotation, methods, etc. may be queried.

  •  String representation of  an instance

The toString() is widely used for printout.

  • Instance Clone

Used for instance copy.

  • finalize method

Overridable method invoked before garbage collection.

  • Equality Test

Used to test another instance is equal to this one.

  • Hash code

Used for Hash indexing.

 

Leave a comment