OBJECT class in Java :
Object is at the top of class hierarchy in java.
Every class in the Java system is a descendent (direct or indirect) of the
The
Mainly below methods are provided by Object class :
The
Following methods are when used , generally over-ridden as per behavior required in the over riding class :
Object is at the top of class hierarchy in java.
Every class in the Java system is a descendent (direct or indirect) of the
Object class.The
Object
class defines the basic state and behavior that all objects must have,
such as the ability to compare oneself to another object, to convert to
a string, to wait on a condition variable, to notify other objects that
a condition variable has changed, and to return the object's class.Mainly below methods are provided by Object class :
| public String toString() | returns the string representation of this object. |
| protected Object clone() throws CloneNotSupportedException | creates and returns the exact copy (clone) of this object. |
| public boolean equals(Object obj) | compares the given object to this object. |
| public int hashCode() | returns the hashcode number for this object. |
| public final Class getClass() | returns the Class class object of this object. The Class class can further be used to get the metadata of this class. |
| public final void notify() | wakes up single thread, waiting on this object's monitor. |
| public final void notifyAll() | wakes up all the threads, waiting on this object's monitor. |
| public final void wait(long timeout)throws InterruptedException | causes the current thread to wait for the specified milliseconds, until another thread notifies (invokes notify() or notifyAll() method). |
| public final void wait(long timeout,int nanos)throws InterruptedException | causes the current thread to wait for the specified miliseconds and nanoseconds, until another thread notifies (invokes notify() or notifyAll() method). |
| public final void wait()throws InterruptedException | causes the current thread to wait, until another thread notifies (invokes notify() or notifyAll() method). |
| protected void finalize()throws Throwable | is invoked by the garbage collector before object is being garbage collected. |
The
notify, notifyAll, and wait methods of Object helps in synchronizing the activities of independently running threads in a programFollowing methods are when used , generally over-ridden as per behavior required in the over riding class :
clone(), equals(Object obj), finalize(), getClass(), hashCode(), toString()
Comments
Post a Comment