The javap command disassembles a class file. The javap command displays information about the fields,constructors and methods present in a class file.
Syntax
Let's see how to use javap tool or command.
Example #1
snippet
javap fully_class_name
Example #2
Example to use javap tool
snippet
javap java.lang.Object
Output
Compiled from "Object.java"
public class java.lang.Object {
public java.lang.Object();
public final native java.lang.Class<?> getClass();
public native int hashCode();
public boolean equals(java.lang.Object);
protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException;
public java.lang.String toString();
public final native void notify();
public final native void notifyAll();
public final native void wait(long) throws java.lang.InterruptedException;
public final void wait(long, int) throws java.lang.InterruptedException;
public final void wait() throws java.lang.InterruptedException;
protected void finalize() throws java.lang.Throwable;
static {};
}
Example #3
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");
}
}
Example #4
Now let's use the javap tool to disassemble the class file.
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.
Example
Output
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.
Option | Description |
---|
-help | prints the help message. |
-l | prints line number and local variable |
-c | disassembles the code |
-s | prints internal type signature |
-sysinfo | shows system info (path, size, date, MD5 hash) |
-constants | shows static final constants |
-version | shows version information |