Source Code : Using Reflection to browse a java class
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Using Reflection to browse a java class
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Main {
public static void main(String argv[]) throws Exception{
String className = "String";
Class c = Class.forName(className);
Constructor cst[] = c.getDeclaredConstructors();
// get fields from the Class object
Field f[] = c.getDeclaredFields();
// get methods from the Class object
Method m[] = c.getDeclaredMethods();
// filling the constructors list box
for (int i = 0; i < cst.length; i++) {
System.out.println(cst[i].getName());
}
// filling the fields list box
for (int i = 0; i < f.length; i++) {
System.out.println(f[i].getName());
}
// filling the methods list box
for (int i = 0; i < m.length; i++) {
System.out.println(m[i].getName());
}
}
}
Thank with us