Understanding javap tool

The javap command disassembles a class file. The javap command displays information about the fields,constructors and methods present in a class file.

Syntax to use javap tool

Let's see how to use javap tool or command.

snippet
javap fully_class_name

Example to use javap tool

snippet
javap java.lang.Object
Output:
Output

Another example to use javap tool for your class

Let's use the javap command for our java file.

snippet
class Simple{
public static void main(String args[]){
System.out.println("hello java");
}
}

Now let's use the javap tool to disassemble the class file.

snippet
javap Simple
Output:
snippet
Compiled from ".java"
class Simple {
  Simple();
  public static void main(java.lang.String[]);
}

javap -c command

You can use the javap -c command to see disassembled code. The code that reflects the java bytecode.

snippet
javap -c Simple
Output:
snippet
Compiled from ".java"
class Simple {
  Simple();
    Code:
       0: aload_0       
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return        

  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #3                  // String hello java
       5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: return        
}

Options of javap tool

The important options of javap tool are as follows.

OptionDescription
-helpprints the help message.
-lprints line number and local variable
-cdisassembles the code
-sprints internal type signature
-sysinfoshows system info (path, size, date, MD5 hash)
-constantsshows static final constants
-versionshows version information
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents