Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Nov 29, 2001



Application Security Testing: An Integral Part of DevOps

Print Out the List of Fields and Methods Declared in Any Class

Sometimes, it is essential to know the fields and methods that are declared in a particular class. This is all the more important when there is no access to the source code of the class. This code fragment can be used to print all the fields and methods in any given class.
import java.lang.reflect.*;
public class ClassMetaData {

 public static void main(String[] args) {
   try {
      Class c = Class.forName("ClassMetaData");
      Field[] fields = c.getDeclaredFields();
      System.out.println("List of declared fields _
are . . .");
      for (int i = 0 ; i < fields.length; i++)

      Method[] methods = c.getDeclaredMethods();
      System.out.println("List of declared methods _
are . . .");
      for (int i = 0; i < methods.length; i++)
   catch(ClassNotFoundException excep) {
      System.err.println("Unable to find class");
Shashank Tanksali
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date