Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

OBJECT CLASS

BY:-

Rohan.Ranade Sumit.Handa

Introduction

The Object class sits at the top of the class hierarchy tree in the Java development environment. 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.

METHOD INDEX

Clone():-Creates a clone of this Object. Notify():- Wakes up a single thread that is waiting on this ojects monitor.

Equals(Object):-Compares two Objects for equality.


Get class():- Returns the class of this object.

Hashcode():- Returns a hashcode to this oject.


Tostring():- returns a string representation ofa object

GET CLASS
public final native Class getClass() Returns: The object of type Class that represents the runtime class of the object.

HASH CODE
public native int hashCode()
RETURNS:- a hash code value for the object.

The general charactertics of hashCode is: 1.Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer. This integer need not remain consistent from one execution of an application to another execution of the same application. 2.two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.

EQUALS
public boolean equals(Object obj) Compares two Objects for equality.
Returns:- true if the object is same as the oject argument, false otherwise
The equals method implements an equivalence relation:

Equivalence relations

It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. For any reference value x, x.equals(null) should return false.

CLONE
protected native Object clone()
Creates a new object of the same class as this object. It then initializes each of the new object's fields by assigning it the same value as the corresponding field in this object. The clone method of class Object will only clone an object whose class indicates that it is willing for its instances to be cloned. A class indicates that its instances can be cloned by declaring that it implements the Cloneable interface.

toString
public String toString()
Returns:- a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommendedthat all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the atsign character `@', and the unsigned hexadecimal representation of the hash code of the object.

NOTIFY
public final native void notify()
Wakes up a single thread that is waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways: 1. By executing a synchronized instance method of that object. 2. By executing the body of a synchronized statement that synchronizes on the object. 3. For objects of type Class, by executing a synchronized static method of that class.

NOTIFY ALL
public final native 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. This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

WAIT
public final native void wait(long timeout)
Waits to be notified by another thread of a change in this object. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred. 1. Another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. 2. The timeout period, specified by the timeout argument in milliseconds, has elapsed.

FINALIZE
protected void finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup. Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

THANK YOU

You might also like