Example usage for java.lang Class forName

List of usage examples for java.lang Class forName

Introduction

In this page you can find the example usage for java.lang Class forName.

Prototype

@CallerSensitive
public static Class<?> forName(String name, boolean initialize, ClassLoader loader)
        throws ClassNotFoundException 

Source Link

Document

Returns the Class object associated with the class or interface with the given string name, using the given class loader.

Usage

From source file:MyClass.java

public static void main(String[] args) {
    try {//from   w w  w .  j ava2 s  . c om
        String className = "MyClass";
        boolean initialize = false;

        ClassLoader cLoader = Main.class.getClassLoader();
        Class c = Class.forName(className, initialize, cLoader);
        className = "MyClass";
        System.out.println("about to load");
        // Will load and initialize the class
        c = Class.forName(className);
    } catch (ClassNotFoundException e) {
        System.out.println(e.getMessage());
    }
}