Basically the reflection API includes two components: objects representing various parts of a class file and provides a way to extract those objects in a safe and secure way. Java supports several security safeguards and therefore it make sense to provide a set of classes in order to invalidate those safeguards.
The first component provided by the Reflection API
provides a mechanism that fetches information about a class. This mechanism is
developed inside the class named Class. The class
Class is a
special type of the class that provides the universal type for the meta
information to describe objects within the Java system. With in the Java system
Class loaders return objects of type Class. Till now this class includes
three most interesting methods:
Along with these methods some more methods are also added to the class Class. Here is the listing of these methods:
Several new classes were added in order to represent
the objects that these methods would return. Most of these classes are the part
of the package
java.lang.reflect, while some of the new basic type
classes such as
Byte and so on are kept in
package. Decision was taken to put the new classes where they are by putting
classes that represented meta-data in the reflection package and classes that
represented types in the language package.
The Reflection API made a number of changes to class
in order to give the answer of the question regarding the internals of the
class, and a bunch of classes representing the answers given by these new
Reflection is generally used by programs that examine or modify the runtime behavior of applications running in the Java virtual machine. This relatively advanced feature should be used only by developers having a strong grasp of the fundamentals of the language. Or in other words we can say that reflection is a powerful technique that is capable of enabling the applications to perform operations which would otherwise be impossible.
An application can use user-defined classes simply by creating instances of extensibility objects by using their fully-qualified names.
Class Browsers and Visual Development Environments
Debuggers and Test Tools
Debuggers needs to be able for examining the private members on classes. Reflection can be used by test harnesses to systematically call a discoverable set APIs defined on a class, to make sure a high level of code coverage in a test suite.
Recommend the tutorial