Java Class forName() Method

The forName() method of Java Class class returns the Class object associated with the class or interface with the given name in the parameter as String.

Syntax

This method is overloaded in the following ways.

Parameter

module - A module

name - The binary name of the class

className - the fully qualified name of the desired class.

name - the fully qualified name of the desired class

initialize - if true the class will be initialized.

loader - class loader from which the class must be loaded

Returns

class object representing the desired class.

Throws

LinkageError ,ExceptionInInitializerError , ClassNotFoundException SecurityException

Example 1

Test it Now

Output:

Name of Class  = java.lang.ClassLoader
Package Name  = package java.lang, Java Platform API Specification, version 1.8
Interface Name  = [Ljava.lang.Class;@7852e922

Example 2

Test it Now

Output:

Name of Class  = java.lang.ClassLoader
Package Name  = package java.lang, Java Platform API Specification, version 1.8
Interface Name  = [Ljava.lang.Class;@7852e922
Construcors     = [Ljava.lang.reflect.Constructor;@4e25154f
Classes        = [Ljava.lang.Class;@70dea4e

Next TopicJava Class




Latest Courses