Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Thursday 25 May 2017

Java Object Class

 

Object Class

Java Object Class

Object class in java is a super class or parent class or topmost class in java. Every class in java extends or inherit Object class by default. There is no need to use 'extends keyword' to extends or inherit the Object class because Object class are inherited by default in java.

Object class are available in java.lang package.

Object class is the root of the class hierarchy. All objects including arrays implements the method of this class.


Object Class Declaration

Declaration of java.lang.Object class is given below.

public class Object

As we know Object class are inherited by default but if we want to inherit other user defined class then we have to use extends keyword to inherit that class in java.

Every class in java extends Object class directly or indirectly.


Constructor of Object Class

1) Object()

This is empty constructor of Object class.


Java Object Class Methods

There are 11 methods in Object class in java programming language.

These are very useful method, Which is used in java thread, java String and other java programs.

1) protected Object clone()

This method creates and returns a copy of this object.

2) boolean equals(Object obj)

This method is used to compare the given object to this object.

3) protected void finalize()

The finalize method is called by the garbage collector. The finalize method is called just before an object is garbage collected. This method is called by the garbage collector on an object when garbage collector determines that there are no more reference to the object.

4) int hashCode()

This method returns a hashcode value for the object.

HashCode : In java for every objects, JVM generates a unique number which is called hashCode in java. JVM generates a different-different hashCode for differenet-different objects in java.

5)  void notify()

This method wakes up single thread that is waiting on this object's monitor.

6) void notifyAll()

This method wakes up all the thread that are waiting on this object's monitor.

7) toString()

The toString() method provides String representation of an object and this method is also used to convert an object to String.

8) wait()

Causes the current thread to wait until another thread invokes the notify() method or notifyAll() method for this object.

9) wait(long timeout)

Causes the current thread to wait until another thread invokes the notify() method or notifyAll() method for this object or a specified amount of time has elapsed.

10) wait(ling timeout, int nanos)

Causes the current thread to wait until another thread invokes the notify() method or notifyAll() method for this object or some other thread interrupts the current thread or a certain amount of real time has elapsed.

11) public final Class getClass()

This method returns the Class class object of this object. The Class class can further be used to  get metadata of this class.The returned Class object is the object that is locked by static synchronized methods of the represented class. 


Now Here we learned in detail, What is Object class in java and Constructor of Object class and Object class's methods


Share:

0 comments:

Post a Comment

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate