Package java.lang |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public final class java.lang.Class extends java.lang.Object { // Methods public static Class forName(String className); public ClassLoader getClassLoader(); public Class[] getInterfaces(); public String getName(); public Class getSuperclass(); public boolean isInterface(); public Object newInstance(); public String toString(); }
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 in the class loader.
public static Class forName(String className)throws ClassNotFoundExceptionReturns 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")
Return Value:
Returns the Class descriptor for the class with the specified name
Parameter Description className the fully qualified name of the desired class Throw:
If the class could not be found.
public ClassLoader getClassLoader()Determines the class loader for the class.
Return Value:
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.
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.
Return Value:
Returns an array of interfaces implemented by this class.
public String getName()Return Value:
Returns the fully qualified name of the class or interface represented by this object..
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.
Return Value:
Returns the superclass of the class represented by this object.
public boolean isInterface()Return Value:
Returns true if this object represents an interface; false otherwise.
public Object newInstance()throws InstantiationException, IllegalAccessExceptionCreates a new instance of a class.
Return Value:
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.
Throw:
If an application tries to instantiate an abstract class or an interface, or if the instantiation fails for some other reason.
Throw:
If the class or initializer is not accessible.
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.
Return Value:
Returns a string representation of the class object.
Overrides:
toString in class Object .