provided by: 
Originally published at Internet.comJava classes are the main building blocks of a Java application. As developers, we write some classes, but we also use classes developed by others. We rely on the API listings and documentation to learn how to use these "third-party" classes effectively. That works well (at least as well as the quality of the documentation!) in development stages. Java also provides a framework for learning about classes during runtime. That framework is called Reflection and is wrapped as the java.lang.reflect package.

Piroz Mohseni
A number of popular Java technologies/frameworks depend on the Reflection API to function. For example, a JavaBean container uses the Reflection API to learn about the properties and methods of a Bean. Reflection is also used in Remote Method Invocation. With the introduction of Java/XML binding technologies like JAXB, Reflection may also be used to learn about the structure of an XML document by looking at a "class" representation of an XML document. The following example provides a simple explanation of how the Reflection API could be used.
Consider the sample class called Foo shown below. It has three fields: num, c, and test. It also has two constructors. Note that one of the constructors is non-public. It also has three methods, where one (methodB) is labeled as private. public class Foo { public int num; public char c; String test; public Foo() { num = 2; c = 'b'; test= "test"; System.out.println("Foo constructor"); } Foo(int i) { num = i; c = 'b'; test = "test"; System.out.println("Foo constructor with param"); } public void methodA() { System.out.println("Method A"); } private void methodB() { System.out.println("Method B"); } public int methodC(int i, char c) { System.out.println("i = " + i + " c= " + c); return i; } } ...
Read article at Internet.com site