home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Java in a Nutshell

Previous Chapter 25
The java.lang Package
Next
 

25.47 java.lang.Object (JDK 1.0)

This is the root class in Java. All classes are subclasses of Object, and thus all objects can invoke the public and protected methods of this class. equals() tests whether two objects have the same value (i.e., not whether two variables refer to the same object, but whether two distinct objects have byte-for-byte equivalence). For classes that implement the Cloneable interface, clone() makes a byte-for-byte copy of an Object. getClass() returns the Class object associated with any Object, and the notify(), notifyAll(), and wait() methods are used for thread synchronization on a given Object.

A number of these Object methods should be overridden by subclasses of Object. Subclasses should provide their own definition of the toString() method so that they can be used with the string concatenation operator and with the PrintWriter.println() methods. Defining the toString() method for all objects also helps with debugging.

Classes that contain references to other objects may want to override the equals() and clone() methods (for Cloneable objects) so that they recursively call the equals() and clone() methods of the objects referred to within the original object. Some classes, particularly those that override equals(), may also want to override the hashCode() method to provide an appropriate hashcode to be used when storing instances in a Hashtable data structure.

Classes that allocate system resources other than memory (such as file descriptors or windowing system graphic contexts) should override the finalize() method to release these resources when the object is no longer referred to and is about to be garbage collected.

public class Object {
    // Default Constructor: public Object()
    // Public Instance Methods
            public boolean equals(Object obj);
            public final native Class getClass();
            public native int hashCode();
            public final native void notify();
            public final native void notifyAll();
            public String toString();
            public final native void wait(long timeout) throws InterruptedException;
            public final void wait(long timeout, int nanos) throws InterruptedException;
            public final void wait() throws InterruptedException;
    // Protected Instance Methods
            protected native Object clone() throws CloneNotSupportedException;
            protected void finalize() throws Throwable;
}

Extended By:

Many classes

Passed To:

Many methods

Returned By:

Many methods

Type Of:

Event.arg, Event.target, EventObject.source, Image.UndefinedProperty, Reader.lock, ReplicateScaleFilter.outpixbuf, Vector.elementData, Writer.lock


Previous Home Next
java.lang.NumberFormatException (JDK 1.0) Book Index java.lang.OutOfMemoryError (JDK 1.0)

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java










??????????????@Mail.ru