This section provides a tutorial example of how to list all public variables and methods of a class with 'javap' without any options.
In order to test the Java disassembler tool, I wrote this simple Java application
file, Circle.java:
/**
* Circle.java
* Copyright (c) 2006 by Dr. Herong Yang, http://www.herongyang.com/
*/
public class Circle {
public String uom = "Centimeter";
private int x = 0;
private int y = 0;
private int r = 1;
public void setRadius(int radius) {
r = radius;
}
public void setCenter(int centerX, int centerY) {
x = centerX;
y = centerY;
}
public void printRadius() {
System.out.println(r + " " + uom);
}
public void printArea() {
double area = getArea();
System.out.println(area + " " + uom + "^2");
}
private double getArea() {
return 3.14159*r*r;
}
}
To test "javap", we need to compile this source code file into a bytecode class file,
Circle.class:
Now we can see what "javap" will do for use on this bytecode class file:
C:\herong>javap Circle
Compiled from "Circle.java"
public class Circle extends java.lang.Object{
public java.lang.String uom;
public Circle();
public void setRadius(int);
public void setCenter(int, int);
public void printRadius();
public void printArea();
}
Very nice. By default, "javap" print a list of all public variables and methods.