Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.10

Disassembling Java Bytecode Class Files with 'javap -c -private'

This section provides a tutorial example of how to disassemble Java bytecodes with 'javap -c -private' command. The disassembled codes are JVM execution instructions.

Actually, the main function of "javap" is to disassemble Java bytecodes with the "-c" option. The disassembed codes are execution instructions of JVM (Java Virtual Machine).

Now, let's try "javap -c -private" with the bytecode compiled from Circle.java source code.

C:\herong>javap -private Circle

Compiled from "Circle.java"
public class Circle extends java.lang.Object{
public java.lang.String uom;

private int x;

private int y;

private int r;

public Circle();
  Code:
   0:	aload_0
   1:	invokespecial	#1; //Method java/lang/Object."<init>":()V
   4:	aload_0
   5:	ldc	#2; //String Centimeter
   7:	putfield	#3; //Field uom:Ljava/lang/String;
   10:	aload_0
   11:	iconst_0
   12:	putfield	#4; //Field x:I
   15:	aload_0
   16:	iconst_0
   17:	putfield	#5; //Field y:I
   20:	aload_0
   21:	iconst_1
   22:	putfield	#6; //Field r:I
   25:	return

public void setRadius(int);
  Code:
   0:	aload_0
   1:	iload_1
   2:	putfield	#6; //Field r:I
   5:	return

public void setCenter(int, int);
  Code:
   0:	aload_0
   1:	iload_1
   2:	putfield	#4; //Field x:I
   5:	aload_0
   6:	iload_2
   7:	putfield	#5; //Field y:I
   10:	return

...

private double getArea();
  Code:
   0:	ldc2_w	#18; //double 3.14159d
   3:	aload_0
   4:	getfield	#6; //Field r:I
   7:	i2d
   8:	dmul
   9:	aload_0
   10:	getfield	#6; //Field r:I
   13:	i2d
   14:	dmul
   15:	dreturn

}

Note that:

  • I used "-c" and "-private" options together to disassemble both private and public methods.
  • All class level variables are printed out in the disassembled codes as comments like "//Field r:I".
  • Constants are printed out in the disasembled codes as comments like "//double 3.14159d".
  • String constants are also printed out in the disasembled codes as comments like "//String Centimeter". So don't distribute any Java bytecode compiled from source codes that contain any password strings. People can easy find the passwords using the "javap" tool.
  • If you want to understand each statement listed in the disassembled code, you need to read the JVM Specification first.

Sections in This Chapter

'javap' - Java Disassembler Command and Options

Listing Public Variables and Methods with 'javap'

Listing Private Variables and Methods with 'javap -private'

Disassembling Java Bytecode Class Files with 'javap -c -private'

Looking Up Method Signature with 'javap' Command

Dr. Herong Yang, updated in 2008
Disassembling Java Bytecode Class Files with 'javap -c -private'