Class: forName(String classDec) : Class « java.lang « Java by API






Class: forName(String classDec)

   
/*
 * Output:
Constructors:
 public java.awt.Dimension(java.awt.Dimension)
 public java.awt.Dimension(int,int)
 public java.awt.Dimension()
Fields:
 public int java.awt.Dimension.width
 public int java.awt.Dimension.height
Methods:
 public int java.awt.Dimension.hashCode()
 public boolean java.awt.Dimension.equals(java.lang.Object)
 public java.lang.String java.awt.Dimension.toString()
 public java.awt.Dimension java.awt.Dimension.getSize()
 public void java.awt.Dimension.setSize(int,int)
 public void java.awt.Dimension.setSize(double,double)
 public void java.awt.Dimension.setSize(java.awt.Dimension)
 public double java.awt.Dimension.getHeight()
 public double java.awt.Dimension.getWidth()
 public java.lang.Object java.awt.geom.Dimension2D.clone()
 public void java.awt.geom.Dimension2D.setSize(java.awt.geom.Dimension2D)
 public final native java.lang.Class java.lang.Object.getClass()
 public final void java.lang.Object.wait() throws java.lang.InterruptedException
 public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
 public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
 public final native void java.lang.Object.notify()
 public final native void java.lang.Object.notifyAll()
 * */

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MainClass {
  public static void main(String args[]) {
    try {
      Class c = Class.forName("java.awt.Dimension");
      System.out.println("Constructors:");
      Constructor constructors[] = c.getConstructors();
      for (int i = 0; i < constructors.length; i++) {
        System.out.println(" " + constructors[i]);
      }

      System.out.println("Fields:");
      Field fields[] = c.getFields();
      for (int i = 0; i < fields.length; i++) {
        System.out.println(" " + fields[i]);
      }

      System.out.println("Methods:");
      Method methods[] = c.getMethods();
      for (int i = 0; i < methods.length; i++) {
        System.out.println(" " + methods[i]);
      }
    } catch (Exception e) {
      System.out.println("Exception: " + e);
    }
  }
}

           
         
    
    
  








Related examples in the same category

1.Class: Annotation[] getAnnotations()
2.Class: getCanonicalName()
3.Class: getClasses()
4.Class: getComponentType()
5.Class: getConstructors()
6.Class: getConstructor(Class...)
7.Class: getDeclaringClass()
8.Class: getDeclaredConstructors()
9.Class: getDeclaredFields()
10.Class: getDeclaredMethods()
11.Class: getDeclaredMethod(String name, Class... parameterTypes)
12.Class: getEnumConstants()
13.Class: getFields()
14.Class: getGenericInterfaces()
15.Class: getGenericSuperclass()
16.Class: getInterfaces()
17.Class: Method getMethod(String name, Class... parameterTypes)
18.Class: getMethods()
19.Class: getModifiers()
20.Class: getName()
21.Class: getPackage()
22.Class: getProtectionDomain()
23.Class: getResource(String name) (absolute from the classpath)
24.Class: getResource(String name) (relative to the class location)
25.Class: getResourceAsStream(String name)
26.Class: getSuperclass()
27.Class: getTypeParameters()
28.Class: isArray()
29.Class: isAssignableFrom(Class cls)
30.Class: isEnum()
31.Class: isInstance(Object obj)
32.Class: isInterface()
33.Class: newInstance()