home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / Class.java < prev    next >
Text File  |  1996-05-03  |  4KB  |  107 lines

  1. /*
  2.  * @(#)Class.java    1.26 95/12/21  
  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.  * Class objects contain runtime representations of classes.  Every
  24.  * object in the system is an instance of some Class, and for each Class
  25.  * there is one of these descriptor objects. A Class descriptor is not 
  26.  * modifiable at runtime.<p>
  27.  * The following example uses a Class object to print the Class name
  28.  * of an object:
  29.  * <pre>
  30.  *    void printClassName(Object obj) {
  31.  *        System.out.println("The class of " + obj +
  32.  *                   " is " + obj.getClass().getName());
  33.  *    }
  34.  * </pre>
  35.  * @version     1.26, 21 Dec 1995
  36.  */
  37. public final
  38. class Class {
  39.     /**
  40.      * Make sure nobody instantiates this class
  41.      */
  42.     private Class() {}
  43.     
  44.     /**
  45.      * Returns the runtime Class descriptor for the specified Class.
  46.      * For example, the following code fragment returns the runtime
  47.      * Class descriptor for the Class named java.lang.Thread:
  48.      * <pre>
  49.      *        Class t = Class.forName("java.lang.Thread")
  50.      * </pre>
  51.      * @param className    the fully qualified name of the desired Class
  52.      * @exception    ClassNotFoundException If the Class could not be found.
  53.      */
  54.     public static native Class forName(String className) throws ClassNotFoundException;
  55.  
  56.     /**
  57.      * Creates a new instance of this Class.
  58.      * @return         the new instance of this Class.
  59.      * @exception    InstantiationException If you try to instantiate
  60.      *                  an abstract class or an interface, or if
  61.      *            the instantiation fails for some other reason.
  62.      * @exception       IllegalAccessException If the class or initializer
  63.      *                  is not accessible.
  64.      */
  65.     public native Object newInstance() 
  66.      throws InstantiationException, IllegalAccessException;
  67.  
  68.     /**
  69.      * Returns the name of this Class.
  70.      */
  71.     public native String getName();
  72.  
  73.     /**
  74.      * Returns the superclass of this Class.
  75.      */
  76.     public native Class getSuperclass();
  77.  
  78.     /**
  79.      * Returns the interfaces of this Class. An array 
  80.      * of length 0 is returned if this Class implements no interfaces.
  81.      */
  82.     public native Class getInterfaces()[];
  83.  
  84.     /**
  85.      * Returns the Class loader of this Class.  Returns null
  86.      *        if this Class does not have a Class loader.
  87.      * @see    ClassLoader
  88.      */
  89.     public native ClassLoader getClassLoader();
  90.  
  91.     /**
  92.      * Returns a boolean indicating whether or not this Class is an 
  93.      * interface.
  94.      */
  95.     public native boolean isInterface();
  96.  
  97.     /**
  98.      * Returns the name of this class or interface. The word 
  99.      * "class" is prepended if it is a Class; the word "interface"
  100.      * is prepended if it is an interface.
  101.      */
  102.     public String toString() {
  103.     return (isInterface() ? "interface " : "class ") + getName();
  104.     }
  105. }
  106.  
  107.