home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / java.z / Object.java < prev    next >
Text File  |  1996-05-03  |  6KB  |  165 lines

  1. /*
  2.  * @(#)Object.java    1.35 96/03/30  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. /**
  23.  * The root of the Class hierarchy.  Every Class in the system
  24.  * has Object as its ultimate parent.  Every variable and method
  25.  * defined here is available in every Object. 
  26.  * @see        Class
  27.  * @version     1.35, 30 Mar 1996
  28.  */
  29. public class Object {
  30.     /**
  31.      * Returns the Class of this Object. Java has a runtime
  32.      * representation for classes- a descriptor of type Class- 
  33.      * which the method getClass() returns for any Object.
  34.      */
  35.     public final native Class getClass();
  36.  
  37.     /**
  38.      * Returns a hashcode for this Object.
  39.      * Each Object in the Java system has a hashcode. The hashcode
  40.      * is a number that is usually different for different Objects.
  41.      * It is used when storing Objects in hashtables.
  42.      * Note: hashcodes can be negative as well as positive.
  43.      * @see        java.util.Hashtable
  44.      */
  45.     public native int hashCode();
  46.  
  47.     /**
  48.      * Compares two Objects for equality.
  49.      * Returns a boolean that indicates whether this Object is equivalent 
  50.      * to the specified Object. This method is used when an Object is stored
  51.      * in a hashtable.
  52.      * @param    obj    the Object to compare with
  53.      * @return    true if these Objects are equal; false otherwise.
  54.      * @see        java.util.Hashtable
  55.      */
  56.     public boolean equals(Object obj) {
  57.     return (this == obj);
  58.     }
  59.  
  60.     /**
  61.      * Creates a clone of the object. A new instance is allocated and a 
  62.      * bitwise clone of the current object is place in the new object.
  63.      * @return        a clone of this Object.
  64.      * @exception    OutOfMemoryError If there is not enough memory.
  65.      * @exception    CloneNotSupportedException Object explicitly does not
  66.      *                      want to be cloned, or it does not support the
  67.      *                      Cloneable interface.
  68.      */
  69.     protected native Object clone() throws CloneNotSupportedException;
  70.  
  71.     /**
  72.      * Returns a String that represents the value of this Object.  It is recommended
  73.      * that all subclasses override this method.
  74.      */
  75.     public String toString() {
  76.     return getClass().getName() + "@" + Integer.toHexString(hashCode());
  77.     }
  78.  
  79.     /**
  80.      * Notifies a single waiting thread on a change in condition of another thread. 
  81.      * The thread effecting the change notifies the waiting thread
  82.      * using notify(). Threads that want to wait for a condition to 
  83.      * change before proceeding can call wait(). <p>
  84.      * <em>The method notify() can only be called by the thread that is
  85.      * the owner of the current object's monitor.</em>
  86.      *
  87.      * @exception    IllegalMonitorStateException If the current thread
  88.      *                is not the owner of the Object's monitor.
  89.      * @see        Object#wait
  90.      * @see        Object#notifyAll
  91.      */
  92.     public final native void notify();
  93.  
  94.     /**
  95.      * Notifies all of the threads waiting for a condition to change.
  96.      * Threads that are waiting are generally waiting for another thread to 
  97.      * change some condition. Thus, the thread effecting a change that more 
  98.      * than one thread is waiting for notifies all the waiting threads using
  99.      * the method notifyAll(). Threads that want to wait for a condition to 
  100.      * change before proceeding can call wait(). <p>
  101.      * <em>The method notifyAll() can only be called by the thread that is
  102.      * the owner of the current object's monitor.</em>
  103.      *
  104.      * @exception    IllegalMonitorStateException If the current thread
  105.      *                 is not the owner of the Object's monitor.
  106.      * @see        Object#wait
  107.      * @see        Object#notify
  108.      */
  109.     public final native void notifyAll();
  110.  
  111.     /**
  112.      * Causes a thread to wait until it is notified or the specified timeout
  113.      * expires. <p>
  114.      * <em>The method wait() can only be called from within a synchronized method.</em>
  115.      *
  116.      * @param timeout    the maximum time to wait in milliseconds
  117.      * @exception    IllegalMonitorStateException If the current thread
  118.      *                is not the owner of the Object's monitor.
  119.      * @exception     InterruptedException Another thread has interrupted
  120.      *                this thread. 
  121.      */
  122.     public final native void wait(long timeout) throws InterruptedException;
  123.  
  124.     /**
  125.      * More accurate wait.
  126.      * <em>The method wait() can only be called by the thread that is
  127.      * the owner of the current object's monitor.</em>
  128.      *
  129.      * @param timeout    the maximum time to wait in milliseconds
  130.      * @param nano      additional time, in nanoseconds range 0-999999
  131.      * @exception    IllegalMonitorStateException If the current thread
  132.      *                is not the owner of the Object's monitor.
  133.      * @exception     InterruptedException Another thread has interrupted
  134.      *                this thread. 
  135.      */
  136.     public final void wait(long timeout, int nanos) throws InterruptedException {
  137.     if (nanos >= 500000 || (nanos != 0 && timeout==0))
  138.         timeout++;
  139.     wait(timeout);
  140.     }
  141.  
  142.     /**
  143.      * Causes a thread to wait forever until it is notified. <p>
  144.      * <em>The method wait() can only be called from within a synchronized method</em>
  145.      *
  146.      * @exception    IllegalMonitorStateException If the current thread
  147.      *                is not the owner of the Object's monitor.
  148.      * @exception     InterruptedException Another thread has interrupted
  149.      *                this thread. 
  150.      */
  151.     public final void wait() throws InterruptedException {
  152.     wait(0);
  153.     }
  154.  
  155.     /**
  156.      * Code to perform when this object is garbage collected.  
  157.      * The default is that nothing needs to be performed.
  158.      * 
  159.      * Any exception thrown by a finalize method causes the finalization to
  160.      * halt.  But otherwise, it is ignored.
  161.      */
  162.     protected void finalize() throws Throwable { }
  163. }
  164.  
  165.