The run time behaviour of a class can be examined and modified at run time,this process is called java reflection. To examine and change the run time behaviour of a classjava.lang.Class is used which provides many methods to modify run time behaviour. java.lang.reflect packages provide classes for java reflection. Java reflection API is to be used with debugger and test tools.
Thisclass performs two tasks:
For examining and changing run time behaviour of class,java.lang.class provides various methods.
It also provides methods to get information i.e meta data of a class at run time.
Few methods of java.lang.Class class are:
public String getName()
public static Class forName(String className)throws ClassNotFoundException
public Object newInstance()throws InstantiationException,IllegalAccessException.
A program to demonstrate method of java.lang.class. This program is using public String forName() method.
public static void main(String args)
public String forName() returns the instance of class class i.e the class is loaded dynamically. This method cannot be used with primitive types and only be used when full name of class is known.