Class forName() method in Java with Examples Last Updated : 01 Jun, 2021 Comments Improve Suggest changes Like Article Like Report 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 parameter className which is the Class for which its instance is required.Return Value: This method returns the instance of this Class with the specified class name.Exception: This method throws following Exceptions: LinkageError: if the linkage failsExceptionInInitializerError: if the initialization provoked by this method failsClassNotFoundException: if the class cannot be located 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 { // get the Class instance using forName method Class c1 = Class.forName("java.lang.String"); 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 { // get the Class instance using forName method Class c1 = Class.forName("java.lang.Integer"); 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- Comment More infoAdvertise with us Next Article Class forName() 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 getName() method in Java with Examples The getName() method of java.lang.Class class is used to get the name of this entity. This entity can be a class, an array, an interface, etc. The method returns the name of the entity as a String.Syntax: public String getName() Parameter: This method does not accept any parameter.Return Value: This 1 min read Charset forName() method in Java with Examples The forName() method is a built-in method of the java.nio.charset returns a charset object for the named charset. In this function we pass a canonical name or an alias and its respective charset name is returned. Syntax: public static Charset forName?(String charsetName) Parameters: The function acc 3 min read Class getTypeName() method in Java with Examples The getTypeName() method of java.lang.Class class is used to get the type name of this class, which provides the information about this class' type. The method returns the type name of this class in the form of String. Syntax: public String getTypeName() Parameter: This method does not accept any pa 2 min read Class getSimpleName() method in Java with Examples The getSimpleName() method of java.lang.Class class is used to get the simple name of this class, as given in the sourcecode. The method returns the simple name of this class in the form of String. If this class is anonymous, then this method returns empty string.Syntax: public String getSimpleName( 2 min read Class getField() method in Java with Examples The getField() method of java.lang.Class class is used to get the specified field of this class, which is the field that is public and its members. The method returns the specified field of this class in the form of Field objects. Syntax: public Field getField(String fieldName) throws NoSuchFieldExc 2 min read Like