«Back to Home

Core Java

Topics

Javap Tool In Java

Javap Tool
 
In Java, javap command disassembles a class file and it displays the information about the fields, constructors and methods, present in a class file.
 
Syntax

javap fully_class_name
 
For example

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 {};
}
 
Let’s see another example to use javap tool for our class, given below.
 
Code
  1. class JavapToolExample {  
  2.     public static void main(String args[]) {  
  3.         System.out.println("Welcome to Java world");  
  4.     }  
  5. }  
At this time, let's use the javap tool to disassemble the class file.
 
javap JavapToolExample
 
Output

Compiled from ".java"
class JavapToolExample {
JavapToolExample();
public static void main(java.lang.String[]);
}
 
javap -c command

We can use the javap -c command to see the disassembled code and the code that reflects Java bytecode.
 
javap -c JavapToolExample
 
Output

Compiled from ".java"
class JavapToolExample {
JavapToolExample ();
 
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
}
 
The important options of javap tool are,
 
-help

It prints the help message.
 
-l

It prints line number and local variable
 
-c

It disassembles the code
 
-s

It prints internal type signature
 
-sysinfo
 
It shows system info (path, size, date, MD5 hash)
 
-constants

It shows static final constants
 
-version

It shows version information
 
Summary

Thus, we learnt that javap command disassembles a class file and it displays the information about the fields, constructors and methods, present in a class file in Java.