Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

JavaBeansTM Short Course
Help: Reflective Programming with Freud

By MageLang Institute

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

Help is available for each task, or you can go straight to the solution source code.

Task 1

Import the reflection library.
import java.lang.reflect.*;

Task 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.
The Class.getDeclaredMethods method lists all methods of a class. The Class.getMethods method includes those methods inherited.

Task 3

Within listClassMethods: for each method of the class, list the modifiers, return type, name, and parameter types.
  • The Method.getModifiers method lists a method's modifiers.
  • The Method.getReturnType method reports a method's return type.
  • The Method.getName method reports a method's name.
  • The Method.getParameterTypes method lists a method's parameter classes.
  • The Method.getExceptionTypes method lists the exceptions a method throws. However, this does not work with the 1.1 JDK.

The Method.toString method could be used, but we do not want each method name prefixed by the name of the class it belongs to.

The private getTypeName method can be used to display the various parameter types. If you do not use this method, you have to convert each array parameter type yourself.

For those unfamiliar with PrintWriter, this is the 1.1 replacement class for PrintStream.

Copyright © 1997 MageLang Institute. All Rights Reserved.

[ This page was updated: 10-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.