How to peek quickly inside the .class files using javap

If you need just need to quickly see the name of the methods of a specific Java class or you want to take a look at a disassembled code, you can use javap. If your JDK is properly installed and you have setup your PATH and CLASSPATH properly, then you can already use javap–it’s executable file is located in /Path/To/YourJDK/Installation/bin.

Basic use of javap

$ javap java.lang.String

This will print out (to the standard output, your monitor) all the method signatures of java.lang.String, pretty much what you will find in the JDK documentation, only without the brief explanations–although not as complete as the JDK documentation, it’s at a quick way to just look at at the method signatures of specific classes. This is a handy technique to have while coding because you can quickly access the exact definitions for method signatures.

If you want to learn more about javap, all you’ve got to do is to type javap -help in the command line so that you can see all of it’s options. I’m including it here for your reference.

$ javap -help
Usage: javap
 ...

where options include:
   -c                        Disassemble the code
   -classpath
     Specify where to find user class files
   -extdirs            Override location of installed extensions
   -help                     Print this usage message
   -J                  Pass  directly to the runtime system
   -l                        Print line number and local variable tables
   -public                   Show only public classes and members
   -protected                Show protected/public classes and members
   -package                  Show package/protected/public classes
                             and members (default)
   -private                  Show all classes and members
   -s                        Print internal type signatures
   -bootclasspath
 Override location of class files loaded
                             by the bootstrap class loader
   -verbose                  Print stack size, number of locals and args for methods
                             If verifying, print reasons for failure
If you want to show appreciation for my efforts dear reader, you could buy me a tall hazel nut Americano ($2) via PayPal. Thanks
Post navigation
(previous post)
(next post)
| | | | .

{0 Comments .. you can add one }

Leave a comment