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.
Example to use javap tool
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.
- 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.
Output:
- 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.
Output:
- Compiled from ".java"
- class Simple {
- Simple();
- Code:
- 0: aload_0
- 1: invokespecial #1
- 4: return
-
- public static void main(java.lang.String[]);
- Code:
- 0: getstatic #2
- 3: ldc #3
- 5: invokevirtual #4
- 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 |
No comments:
Post a Comment