Name

java.lang.Class

Synopsis

This class is a much smaller counterpart to the J2SE Class class. It represents a Java class, array, or interface. A class can be dynamically loaded using the static forName() method, which takes the fully qualified name of the class and returns a Class object. The isArray() and isInterface() methods test whether the class is an array or interface, respectively. To test if a specific object is an instance of this class, pass the object into the isInstance() method. Use the newInstance() method to create an object by invoking its zero-argument constructor. Finally, getResourceAsStream() can be used to load external resources (such as bitmap images) into an input stream.

public final classClass {
   
   // static methods
   public static native Class forName(String className)
      throws java.lang.ClassNotFoundException;

   // public instance methods
   public String getName();
   public InputStream getResourceAsStream(String name);
   public boolean isArray();    
   public boolean isAssignableFrom(Class cls);
   public boolean isInstance(Object obj);
   public boolean isInterface();
   public Object newInstance() throws java.lang.InstantiationException,
      java.lang.IllegalAccessException;
   public String toString();
}

Get Wireless Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.