Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information JDC Resources DukeDollars Early Access

Java Cup Logo

JDC Applets
(chat, newsreader, calendar)

Log Out

Online Training
shadowSearchFAQFeedback

Course Notes Table of Contents
Exercises | Online Training Index

Reflective Programming with Freud
MageLang Institute

[Help | Solution | API Docs | Behavior | Course Notes | Exercises]

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
May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved