Methods of Object class in java with brief descriptions – The java.lang.Object class is the super class of all classes whether the class is predefined or user defined class. Object class is by default inherited whether we extend explicitly or not.
Methods of object class in java :
- protected native Object clone() throws CloneNotSupportedException
- public boolean equals(Object obj)
- protected void finalize() throws Throwable
- public final native Class getClass()
- public native int hashCode()
- public String toString()
- public final native void notify()
- public final native void notifyAll()
- public final void wait(long timeout) throws InterruptedException
- public final void wait(long timeout, int nanoseconds) throws InterruptedException
- public final void wait() throws InterruptedException
Brief description about methods of object class in java
Object clone() : Creates and returns a copy of the existing class object.
boolean equals(Object obj): Used to compare two objects of the same class. Returns true if both objects are equal or else false.
void finalize(): This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object exists.
Class getClass():Returns a hash code value (numeric value) of the object of a class.
String toString():Returns a string representation( textual representation) of the object of a class. We need to override toString method in a class to return string representation.
void notify() : Wakes up a single thread that is waiting on this object’s monitor. If any threads are waiting on this object, one of them is chosen to be awakened
void notifyAll():Wakes up all threads that are waiting on this object’s monitor. A thread waits on an object’s monitor by calling one of the wait methods.
Wait() : A thread release the ownership of the object monitor(lock) and wait until another thread invokes the notify() method or the notifyAll() method for this object.
Java object class from grepcode