LinuxCommandLibrary

javap

Disassemble Java class files

TLDR

Disassemble and list one or more .class files

$ javap [path/to/file1.class path/to/file2.class ...]
copy

Disassemble and list a built-in class file
$ javap java.[package].[class]
copy

Display help
$ javap -help
copy

Display version
$ javap -version
copy

SYNOPSIS

javap [options] class...

PARAMETERS

-help
    Print a help message.

-version
    Print the version information.

-v
    Verbose output; print line number and local variable tables

-c
    Disassemble the code; e.g., the instructions that comprise each of the methods in the class

-s
    Print internal type signatures

-p
    Show all classes and members. Without this option, only public classes and members are shown.

-l
    Print line number and local variable tables.

-classpath <path>
    Specify where to find user class files.

<class>
    The name of the class to disassemble. Can be a path to a class file or a fully qualified class name, depending on the classpath setting.

DESCRIPTION

The javap command is a disassembler for Java class files.
It takes one or more .class files as input and produces a human-readable representation of the compiled bytecode. This allows developers to inspect the internal structure of Java classes, including their methods, fields, and constants.
The output can be directed to standard output or to a specified file. It is especially useful for understanding how the Java compiler translates source code into bytecode instructions and for debugging or reverse engineering Java applications. It can also show information like the constant pool, method signatures, and access flags.

CAVEATS

The output of javap is intended for human consumption, and may not be directly usable as input for other tools. Bytecode is also JVM specific and is an abstraction of machine code.

EXAMPLE USAGE

javap -c MyClass disassembles the methods of MyClass.class and prints the bytecode instructions.
javap -v MyClass provides a more detailed, verbose output, including constant pool information and other metadata.

SECURITY CONSIDERATIONS

While javap is a useful tool, reverse engineering class files can have security implications. Be cautious when analyzing classes from untrusted sources.

HISTORY

The javap command has been part of the Java Development Kit (JDK) since its early versions. It has evolved alongside the Java platform, adding new features and options to support the changing bytecode format and language features. It provides a way to peek inside compiled code.

SEE ALSO

java(1), jdb(1), javac(1)

Copied to clipboard