Understanding javap toolThe 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 toolLet's see how to use javap tool or command. Example to use javap toolOutput: 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 classLet's use the javap command for our java file. FileName: Simple.java Now let's use the javap tool to disassemble the class file. Output: Compiled from "Simple.java" class Simple { Simple(); public static void main(java.lang.String[]); } javap -c commandYou can use the javap -c command to see disassembled code. The code that reflects the java bytecode. Output: Compiled from "Simple.java" class Simple { Simple(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object." Options of javap toolThe important options of javap tool are as follows.
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 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." 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[]); } Next Topiccreating-javap-tool |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India