The Reflection Package

An important innovation that first appeared in Java 1.1 is the Reflection application programming interface (API). Classes in the java.lang.reflect package allow a program to discover the variables, methods, and constructors available in any class, as well as the interfaces implemented. This capability is essential to the JavaBeans concept and to the Serialization API.

Access to class information starts with getting a Class object using the static forName method in the java.lang.Class class, which takes a String input, as shown here:

1.  Class c = Class.forName( namestr );

This object is then used to get instances of the classes in the java.lang.reflect package that are specialized for providing information about the individual ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.