Create new instance


import java.awt.Rectangle;

public class Main {

   public static void main(String[] args) {
      Rectangle r = (Rectangle) createObject("java.awt.Rectangle");
      System.out.println(r.toString());
   }

   static Object createObject(String className) {
      Object object = null;
      try {
          Class classDefinition = Class.forName(className);
          object = classDefinition.newInstance();
      } catch (InstantiationException e) {
          System.out.println(e);
      } catch (IllegalAccessException e) {
          System.out.println(e);
      } catch (ClassNotFoundException e) {
          System.out.println(e);
      }
      return object;
   }
}
Home 
  Java Book 
    Runnable examples  

Reflection Class:
  1. Class modifier: public, abstract or final
  2. Class simple name plus package name
  3. Create new instance
  4. Class reflection, all methods, constructors, parameters, interfaces
  5. Get super class name
  6. Get the class By way of .class
  7. Get unqualified class Name
  8. Is Type Compatible
  9. Is Primitive type
  10. Load a class given its name.