JAVAP(1)

πŸ“¦ version 23.0.2.0, in opensuse-leap 16.0

okay bestie, welcome to the javap page from the JDK Commands manual β€” yes, this is JAVAP(1), and we're about to disassemble one or more class files together πŸ’…βœ¨

πŸŽ€ NAME πŸŽ€

javap β€” disassemble one or more class files. That's the whole vibe, and it's iconic πŸ’–

✨ SYNOPSIS ✨

javap [options] classes...
  • options β€” specifies the command-line options. See Options for javap, bestie 🫢
  • classes β€” specifies one or more classes separated by spaces to be processed for annotations. You can specify a class that can be found in the class path by its file name, URL, or by its fully qualified class name πŸ‘‘

Examples, no cap:

path/to/MyClass.class

jar:file:///path/to/MyJar.jar!/mypkg/MyClass.class

java.lang.Object

🌸 DESCRIPTION 🌸

The javap command disassembles one or more class files. The output depends on the options used. When no options are used, the javap command prints the protected and public fields, and methods of the classes passed to it. Lowkey simple, highkey powerful πŸ’…

The javap command isn't multirelease JAR aware. Using the class path form of the command results in viewing the base entry in all JAR files, multirelease or not. Using the URL form, you can use the URL form of an argument to specify a specific version of a class to be disassembled. The way that matters is real πŸ”₯

The javap command prints its output to stdout. Periodt πŸ’–

Note: In tools that support -- style options, the GNU-style options can use the equal sign (=) instead of a white space to separate the name of an option from its value. Cute little shortcut, bestie πŸŽ€

πŸ’… OPTIONS FOR JAVAP πŸ’…

  • --help, -help, -h, or -? β€” prints a help message for the javap command. Instant help, slay πŸ’–
  • -version β€” prints release information. Version check energy ✨
  • -verbose or -v β€” prints additional information about the selected class. More tea, more info πŸ“
  • -l β€” prints line and local variable tables. Tables but make it bytecode-adjacent πŸ’…
  • -public β€” shows only public classes and members. Public-facing only, main character energy πŸ‘‘
  • -protected β€” shows only protected and public classes and members. A little more access, a little more drama πŸ¦‹
  • -package β€” shows package/protected/public classes and members (this is the default, bestie). The default vibe check 🌈
  • -private or -p β€” shows all classes and members. No secrets, full reveal πŸ™ˆ
  • -c β€” prints disassembled code, for example, the instructions that comprise the Java bytecodes, for each of the methods in the class. The actual bytecode realness πŸ”₯
  • -s β€” prints internal type signatures. Signatures, but internal ✨
  • -sysinfo β€” shows system information (path, size, date, SHA-256 hash) of the class being processed. Receipts and metadata πŸ’–
  • -verify β€” prints additional class verification info. Verification era βœ…
  • -constants β€” shows static final constants. The unchanging icons πŸ’…
  • --module module or -m module β€” specifies the module containing classes to be disassembled. Module gossip πŸŽ€
  • --module-path path β€” specifies where to find application modules. Map to the modules, iykyk πŸ—ΊοΈ
  • --system jdk β€” specifies where to find system modules. System module coordinates 🧚
  • --class-path path, -classpath path, or -cp path β€” specifies the path that the javap command uses to find user class files. It overrides the default or the CLASSPATH environment variable when it's set. Class path but make it explicit πŸ’œ
  • -bootclasspath path β€” overrides the location of bootstrap class files. Bootstrap files, relocated πŸ¦‹
  • --multi-release version β€” specifies the version to select in multi-release JAR files. Version select, no cap πŸŽ€
  • -Joption β€” passes the specified option to the JVM. For example:
javap -J-version
javap -J-Djava.security.manager -J-Djava.security.policy=MyPolicy MyClassName

See Overview of Java Options in java. JVM option handoff, iconic πŸ’–

🌈 JAVAP EXAMPLE 🌈

Compile the following HelloWorldFrame class:

import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class HelloWorldFrame extends JFrame {

   String message = "Hello World!";

   public HelloWorldFrame(){
        setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                g.drawString(message, 15, 30);
            }
        });
        setSize(100, 100);
    }
    public static void main(String[] args) {
        HelloWorldFrame frame = new HelloWorldFrame();
        frame.setVisible(true);

    }

}

The output from the javap HelloWorldFrame.class command yields the following:

Compiled from "HelloWorldFrame.java"
public class HelloWorldFrame extends javax.swing.JFrame {
  java.lang.String message;
  public HelloWorldFrame();
  public static void main(java.lang.String[]);
}

The output from the javap -c HelloWorldFrame.class command yields the following:

Compiled from "HelloWorldFrame.java"
public class HelloWorldFrame extends javax.swing.JFrame {
  java.lang.String message;

  public HelloWorldFrame();
    Code:
       0: aload_0
       1: invokespecial #1        // Method javax/swing/JFrame."<init>":()V
       4: aload_0
       5: ldc           #2        // String Hello World!
       7: putfield      #3        // Field message:Ljava/lang/String;
      10: aload_0
      11: new           #4        // class HelloWorldFrame$1
      14: dup
      15: aload_0
      16: invokespecial #5        // Method HelloWorldFrame$1."<init>":(LHelloWorldFrame;)V
      19: invokevirtual #6        // Method setContentPane:(Ljava/awt/Container;)V
      22: aload_0
      23: bipush        100
      25: bipush        100
      27: invokevirtual #7        // Method setSize:(II)V
      30: return

  public static void main(java.lang.String[]);
    Code:
       0: new           #8        // class HelloWorldFrame
       3: dup
       4: invokespecial #9        // Method "<init>":()V
       7: astore_1
       8: aload_1
       9: iconst_1
      10: invokevirtual #10       // Method setVisible:(Z)V
      13: return
}

kisses bestie, this whole page is from JDK 23, dated 2024 β€” go disassemble something iconic πŸ’…πŸŽ€

πŸ“¦ where this page comes from