Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

JavaBeans Short Course

 
Training Index

Short Course

[Tutorial Contents]
[Behavior] [Help] [API Docs] [Solution]



Skeleton Code

Use of the reflection API is important when creating tools. They need to be able to inspect Java Beans to see how they work. This exercise shows you how to duplicate javap functionality through the use of the Reflection/Introspection capabilities of Java.

Perform the following tasks:

  1. Import the reflection library.

  2. The skeleton code currently lists class variables and constructors of any class requested. It is your job to have it also list all the methods. The framework is included, you only need to complete the listClassMethods method.

  3. Within listClassMethods: for each method of the class, list the modifiers, return type, name, and parameter types.

As time permits, you can do other things with this. To name just a few:

  • Sort each list.
  • Group private, protected, and public items together.
  • For classes in java.lang, chop that part of their name off.
  • Catch security exceptions so this will run unsigned in an applet, without generating lots of stack traces.
  • List only those methods that accept a user provided parameter list.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

Copyright © 1997 MageLang Institute. All Rights Reserved.