Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyze Java class files?

I have a Java .class-file. Now I'd like to find out which methods an fields it provides to the outside world.

I'd like to get a list of all methods and fields plus their visibility. The output could be:

1) final static String CONST = "Test"
2) final public void print(String)
3) protected(com.stackoverflow.package) void pprint(String)
like image 674
Edward Avatar asked Dec 20 '22 10:12

Edward


2 Answers

Use javap

javap DocFooter.class

To get the static final constants

javap -constants DocFooter.class

Check this out

like image 180
Srinivasu Avatar answered Jan 03 '23 05:01

Srinivasu


For every class with in the JVM there is object of the type Class. You can query on this object to get all the info on that particular class.

Class myClass = MyClass.class Method method[] = myClass.getDeclaredMethods();

Refer to Java doc for further info, http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html

If you just want to look at the class content then there are editors like djCompiler etc which does a pretty good job.

like image 45
Santo Avatar answered Jan 03 '23 03:01

Santo