//Reflection enables Java code to discover information about the fields, //methods and constructors of loaded classes, and to use reflected fields, //methods, and constructors to operate on their underlying counterparts on //objects, within security restrictions. The API accommodates applications //that need access to either the public members of a target object //(based on its runtime class) or the members declared by a given class. import java.lang.reflect.*; public class DumpClass { public static void main(String args[]) { try { Class c = Class.forName(args[0]); dumpMethods(c); dumpConstructors(c); dumpFields(c); } catch (Throwable e) { System.err.println(e); } } private static void dumpMethods(Class c) { System.out.println("______________________________Methods_____________________________"); Method m[] = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) { System.out.println(m[i].toString()); } } private static void dumpConstructors(Class c) { System.out.println("____________________________Constructors_____________________________"); Constructor ctorlist[] = c.getDeclaredConstructors(); for (int i = 0; i < ctorlist.length; i++) { Constructor ct = ctorlist[i]; System.out.println("name = " + ct.getName()); System.out.println("decl class = " + ct.getDeclaringClass()); Class pvec[] = ct.getParameterTypes(); for (int j = 0; j < pvec.length; j++) { System.out.println("param #" + j + " " + pvec[j]); } Class evec[] = ct.getExceptionTypes(); for (int j = 0; j < evec.length; j++) { System.out.println("exc #" + j + " " + evec[j]); } System.out.println("-----"); } } private static void dumpFields(Class c) { System.out.println("______________________________Fields_____________________________"); Field fieldlist[] = c.getDeclaredFields(); for (int i = 0; i < fieldlist.length; i++) { Field fld = fieldlist[i]; System.out.println("name= " + fld.getName()); System.out.println("decl class = " + fld.getDeclaringClass()); System.out.println("type= " + fld.getType()); int mod = fld.getModifiers(); System.out.println("modifiers = " + Modifier.toString(mod)); System.out.println("-----"); } } }