Video in progress

What is the javap tool for?

javap is the JDK's disassembler. It shows the list of methods inside a .class file, the bytecode with -c, and the constant pool and version with -v. It is handy for checking what the compiler actually did.

📖 Answer

If you don't have the source code at hand, or want to know how javac transformed your code, javap helps.

public class Sum {
    int add(int a, int b) { return a + b; }
}
javac Sum.java
javap -c Sum
int add(int, int);
  Code:
     0: iload_1
     1: iload_2
     2: iadd
     3: ireturn

What you check with it in practice:

  • that string concatenation became invokedynamic (StringConcatFactory) in Java 9+;
  • how a lambda was compiled;
  • where autoboxing is calling Integer.valueOf;
  • which public methods a class in a jar has (javap -cp lib.jar com.lib.Client).

It is not a decompiler: it doesn't give you the Java code back. For that, IntelliJ's built-in decompiler is more convenient.