Class forName(String, boolean, ClassLoader) method in Java with Examples Last Updated : 01 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The forName(String, boolean, ClassLoader) method of java.lang.Class class is used to get the instance of this Class with the specified class name, using the specified class loader. The class is initialized only if the initialize parameter is true and if it has not been initialized earlier.Syntax: public static Class<T> forName(String className, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException Parameter: This method accepts following parameters: className which is the Class for which its instance is required.initialize which is the boolean to state if this class instance needs to be initialized or not.classLoader which is the ClassLoader from which this Class must be loaded. Return Value: This method returns the instance of this Class fetched using the specified parameters.Exception: This method throws following Exceptions: LinkageError: if the linkage failsExceptionInInitializerError: if the initialization provoked by this method failsClassNotFoundException: if the class cannot be locatedSecurityException: if a security manager is present, and the loader is null, and the caller's class loader is not null, and the caller does not have the RuntimePermission("getClassLoader") Below programs demonstrate the forName() method.Example 1: Java // Java program to demonstrate forName() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for this class Class myClass = Class.forName("Test"); ClassLoader loader = myClass.getClassLoader(); // get the Class instance using forName method Class c1 = Class.forName("java.lang.String", true, loader); System.out.print("Class represented by c1: " + c1.toString()); } } Output: Class represented by c1: class java.lang.String Example 2: Java // Java program to demonstrate forName() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for this class Class myClass = Class.forName("Test"); ClassLoader loader = myClass.getClassLoader(); // get the Class instance using forName method Class c1 = Class.forName("java.lang.Integer", false, loader); System.out.print("Class represented by c1: " + c1.toString()); } } Output: Class represented by c1: class java.lang.Integer Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#forName-java.lang.String-boolean-java.lang.ClassLoader- Comment More infoAdvertise with us Next Article Class forName(String, boolean, ClassLoader) method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class forName() method in Java with Examples The forName() method of java.lang.Class class is used to get the instance of this Class with the specified class name. This class name is specified as the string parameter.Syntax: public static Class<T> forName(String className) throws ClassNotFoundException Parameter: This method accepts the 1 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Boolean compare() method in Java with Examples The compare() method of Boolean class is a built in method in Java which is used to compare two boolean values. It is a static method, so it can be called without creating any object of the Boolean class i.e. directly using the class name. Syntax: Boolean.compare(boolean a, boolean b) Parameters: It 2 min read Boolean equals() method in Java with examples The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object. Syntax: BooleanObject.equals(Object ob) Parameter: It take a parameter ob of type Object as input which is the instance to be compared. Return Type: The return type is boolean. It re 2 min read Boolean booleanValue() method in Java with examples The booleanValue() method of Boolean Class is a built in method in java which is used to return the primitive boolean value of instance which is used to call the method booleanValue(). Syntax BooleanObject.booleanValue() Return Value: It returns a primitive boolean value. Below are the examples to i 1 min read Like