java.lang
Class Class

java.lang.Object
  |
  +--java.lang.Class

public final class Class
extends Object

Note: This class is built into the DVM. Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

The following example uses a Class object to print the class name of an object:

     void printClassName(Object obj) {
         System.out.println("The class of " + obj +
                            " is " + obj.getClass().getName());
     }
 

Since:
JDK1.0
Version:
1.107, 02/02/00
Author:
unascribed
See Also:
ClassLoader.defineClass(byte[], int, int)

Method Summary
 String getName()
          Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.
 String toString()
          Converts the object to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Method Detail

getName

public String getName()
Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.

If this Class object represents a class of arrays, then the internal form of the name consists of the name of the element type in Java signature format, preceded by one or more "[" characters representing the depth of array nesting. Thus:

 (new Object[3]).getClass().getName()
 
returns "[Ljava.lang.Object;" and:
 (new int[3][4][5][6][7][8][9]).getClass().getName()
 
returns "[[[[[[[I". The encoding of element type names is as follows:
 B            byte
 C            char
 D            double
 F            float
 I            int
 J            long
 Lclassname;  class or interface
 S            short
 Z            boolean
 
The class or interface name classname is given in fully qualified form as shown in the example above.

Returns:
the fully qualified name of the class or interface represented by this object.

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 by the fully qualified name of the class in the format returned by getName. If this Class object represents a primitive type, this method returns the name of the primitive type. If this Class object represents void this method returns "void".

Overrides:
toString in class Object
Returns:
a string representation of this class object.