Class.forName(String name, boolean initialize, ClassLoader loader) has the following syntax.
public static Class <?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException
In the following code shows how to use Class.forName(String name, boolean initialize, ClassLoader loader) method.
/*w w w .j ava2 s . co m*/ public class Main { public static void main(String[] args) throws Exception { Class cls = Class.forName("Main"); ClassLoader cLoader = cls.getClassLoader(); Class cls2 = Class.forName("java.lang.Thread", true, cLoader); System.out.println("Class = " + cls.getName()); System.out.println("Class = " + cls2.getName()); } }
The code above generates the following result.