Packages  This Package  Prev  Next  Index  

§1.3 Class Class

public  final  class  java.lang.Class
    extends  java.lang.Object  (I-§1.12)
{
        // Methods
    public static Class forName(String  className);	§1.3.1
    public ClassLoader getClassLoader();	§1.3.2
    public Class[] getInterfaces();	§1.3.3
    public String getName();	§1.3.4
    public Class getSuperclass();	§1.3.5
    public boolean isInterface();	§1.3.6
    public Object newInstance();	§1.3.7
    public String toString();	§1.3.8
}
Instances of the class Class represent classes and interfaces in a running Java application.

There is no public constructor for the class Class. Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and or by calls to the defineClass method (I-§1.4.2) in the class loader.


Methods

forName

public static Class forName(String className) throws ClassNotFoundException
Returns the Class object associated with the class with the given string name.
For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread:
Class t = Class.forName("java.lang.Thread")
Parameters:
className - the fully qualified name of the desired class
Returns:
the Class descriptor for the class with the specified name
Throws
ClassNotFoundException (I-§1.28)
If the class could not be found.

getClassLoader

public ClassLoader getClassLoader()
Determines the class loader (I-§1.4) for the class.

Returns:
The class loader that created the class or interface represented by this object, or null if the class was not created by a class loader.

getInterfaces

public Class[] getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object..
If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object.
If this object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object.
If the class or interface implements no interfaces, the method returns an array of length 0.
Returns:
an array of interfaces implemented by this class.

getName

public String getName()
Returns:
the fully qualified name of the class or interface represented by this object..

getSuperclass

public Class getSuperclass()
If this object represents any class other than the class Object, then the object that represents the superclass of that class is returned.
If this object is the one that represents the class Object or this object represents an interface, null is returned.
Returns:
the superclass of the class represented by this object.

isInterface

public boolean isInterface()
Returns:
true if this object represents an interface; false otherwise.

newInstance

public Object newInstance() throws InstantiationException, IllegalAccessException
Creates a new instance of a class.
Returns:
A newly allocated instance of the class represented by this object. This is done exactly as if by a new expression with an empty argument list.
Throws
InstantiationException (I-§1.36)
If an application tries to instantiate an abstract class or an interface, or if the instantiation fails for some other reason.
Throws
IllegalAccessException (I-§1.31)
If the class or initializer is not accessible.

toString

public String toString()
Converts the object to a string. The string representation is the string "class" or "interface" followed by a space and then the fully qualified name of the class.
Returns:
a string representation of the class object.
Overrides:
toString in class Object (I-§1.12.9).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com