| next>><<prevUnderstanding javap toolLast Updated : 17 Mar 2025Thejavap commanddisassembles a class file. The javap command displays information about the fields, constructors and methods present in a class file.Syntax to use javap toolLet's see how to use javap tool or command.javap fullyclassnameExample to use javap tooljavap java.lang.ObjectOutput:Compiled from "Object.java"
public class java.lang.Object {
public java.lang.Object;
public final native java.lang.Class<?> obtainClass;
public native int generateHashCode;
public boolean compare(java.lang.Object);
protected native java.lang.Object replicate throws java.lang.CloneNotSupportedException;
public java.lang.String representAsString;
public final native void alert;
public final native void notifyEveryone;
public final native void hold(long) throws java.lang.InterruptedException;
public final void hold(long, int) throws java.lang.InterruptedException;
public final void hold throws java.lang.InterruptedException;
protected void cleanUp throws java.lang.Throwable;
static {};
}Another instance to employ the javap utility for your classLet's utilize the javap directive for our java script.FileName:Basic.javaclass Basic{
public static void main(String parameters){
System.out.println("greetings from java");
}
}Now, let's leverage the javap utility to disassemble the class document.javap BasicOutput:Compiled from "Basic.java"
class Basic {
Basic;
public static void main(java.lang.String);
}javap -c commandYou have the option to utilize the javap -c directive to view disassembled code. The code that mirrors the java bytecode.javap -c BasicOutput:Compiled from "Basic.java"
class Basic {
Basic;
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":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 greetings from java
5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}Options of javap utilityThe essential choices of javap utility 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 informationLet's observe how these choices can be applied with an example. For the subsequent file (XYZ.java), we will utilize the previously mentioned options.FileName:XYZ.javapublic class XYZ
{
// primary method
public static void main(String arguments)
{
// declaration of an integer array
int array = {6, 7, 8, 6, 8, 0, 4};
// Determining the array's size
int size = arr.length;
// Displaying the array's size
System.out.println("The size of the array is " + size);
Print the value at the 8th index of the array using the System.out.println statement with the expression "arr[8]".
}
The following command illustrates the use of javap -c ABC to display the output after compiling the "ABC.java" file:
Compiled from "ABC.java"
public class ABC {
public ABC();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return
The main method in the given Java code creates an array of integers and populates it with specific values. It then retrieves the length of the array and prints it to the console along with a specific element from the array.
The bytecode instructions for this program are as follows:
- Load the value 7 onto the stack
- Create a new array of integers with a length of 7
- Duplicate the array reference
- Store the value 6 at index 0
- Duplicate the array reference
- Store the value 7 at index 1
- Duplicate the array reference
- Store the value 8 at index 2
- Duplicate the array reference
- Store the value 6 at index 3
- Duplicate the array reference
- Store the value 8 at index 4
- Duplicate the array reference
- Store the value 0 at index 5
- Duplicate the array reference
- Store the value 4 at index 6
- Save the array reference in local variable 1
- Get the length of the array and store it in local variable 2
- Print the length of the array to the console
- Print the element at index 8 of the array to the console
The compiled class "ABC" contains a constructor with line number information indicating the source file "ABC.java."
The entry point of the program is the "main" method which takes an array of strings as a parameter. Below is the LineNumberTable for the bytecode instructions:
- line 6: Offset 0
- line 9: Offset 39
- line 12: Offset 42
- line 14: Offset 54
- line 16: Offset 69
When running the command "javap -s ABC", the output shows that the class "ABC" was compiled from the file "ABC.java" and contains a constructor method with the descriptor "V".
public static void main(java.lang.String);
descriptor: ([Ljava/lang/String;)V
}Command:javap -sysinfo ABCOutput:Classfile /C:/Users/Nikhil Kumar/Documents/ABC.class
Last modified Sep 11, 2021; size 970 bytes
SHA-256 checksum 576adf03386399a4691e0ce5b6c5aa5d964b082a1a61299bac5632942e413312
Compiled from "ABC.java"
public class ABC {
public ABC;
public static void main(java.lang.String);
}Command:javap -constants ABCOutput:Compiled from "ABC.java"
public class ABC {
public ABC;
public static void main(java.lang.String);
}Command:javap -version ABCOutput:14
Compiled from "ABC.java"
public class ABC {
public ABC;
public static void main(java.lang.String);
}Next Topiccreating-javap-tool<<prevnext>> | 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 |
| 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 |
The javap utility deconstructs a class file to reveal details regarding the fields, constructors, and methods contained within the file. This tool provides insights into the structure of a Java class file by presenting information about its components.
Syntax to use javap tool
Let's see how to use javap tool or command.
javap fully_class_name
Example to use javap tool
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 {};
}
Another example to use javap tool for your class
Let's use the javap command for our java file.
FileName: Simple.java
class Simple{
public static void main(String args[]){
System.out.println("hello java");
}
}
Next, we will utilize the javap utility to decompile the class file.
javap Simple
Output:
Compiled from "Simple.java"
class Simple {
Simple();
public static void main(java.lang.String[]);
}
javap -c command
To view the disassembled code representing Java bytecode, you can utilize the javap -c command. This command allows you to inspect the bytecode instructions of a Java class.
javap -c Simple
Output:
Compiled from "Simple.java"
class Simple {
Simple();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()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
Here are the essential features of the javap utility:
| 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 |
Let's see how one can use these options with the help of an example. For the following file (ABC.java) we will use the above-mentioned options.
FileName: ABC.java
public class ABC
{
// main method
public static void main(String argvs[])
{
// declaring an integer array
int arr[] = {6, 7, 8, 6, 8, 0, 4};
// caculating size of the array
int size = arr.length;
// printing size of the array
System.out.println("The size of the array is " + size );
System.out.println("The 8th index of the array is " + arr[8] );
}
}
Command: javap -c ABC
Output:
Compiled from "ABC.java"
public class ABC {
public ABC();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return
public static void main(java.lang.String[]);
Code:
0: bipush 7
2: newarray int
4: dup
5: iconst_0
6: bipush 6
8: iastore
9: dup
10: iconst_1
11: bipush 7
13: iastore
14: dup
15: iconst_2
16: bipush 8
18: iastore
19: dup
20: iconst_3
21: bipush 6
23: iastore
24: dup
25: iconst_4
26: bipush 8
28: iastore
29: dup
30: iconst_5
31: iconst_0
32: iastore
33: dup
34: bipush 6
36: iconst_4
37: iastore
38: astore_1
39: aload_1
40: arraylength
41: istore_2
42: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream;
45: iload_2
46: invokedynamic #13, 0 // InvokeDynamic #0:makeConcatWithConstants:(I)Ljava/lang/String;
51: invokevirtual #17 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
54: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream;
57: aload_1
58: bipush 8
60: iaload
61: invokedynamic #23, 0 // InvokeDynamic #1:makeConcatWithConstants:(I)Ljava/lang/String;
66: invokevirtual #17 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
69: return
}
Command: javap -l ABC
Output:
Compiled from "ABC.java"
public class ABC {
public ABC();
LineNumberTable:
line 1: 0
public static void main(java.lang.String[]);
LineNumberTable:
line 6: 0
line 9: 39
line 12: 42
line 14: 54
line 16: 69
}
Command: javap -s ABC
Output:
Compiled from "ABC.java"
public class ABC {
public ABC();
descriptor: ()V
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
}
Command: javap -sysinfo ABC
Output:
Classfile /C:/Users/Nikhil Kumar/Documents/ABC.class
Last modified Sep 11, 2021; size 970 bytes
SHA-256 checksum 576adf03386399a4691e0ce5b6c5aa5d964b082a1a61299bac5632942e413312
Compiled from "ABC.java"
public class ABC {
public ABC();
public static void main(java.lang.String[]);
}
Command: javap -constants ABC
Output:
Compiled from "ABC.java"
public class ABC {
public ABC();
public static void main(java.lang.String[]);
}
Command: javap -version ABC
Output:
14
Compiled from "ABC.java"
public class ABC {
public ABC();
public static void main(java.lang.String[]);
}