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

Listing Public Variables and Methods with 'javap'

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:

C:\herong>javac Circle.java

C:\herong>dir Circle.*

   1,153 Circle.class
     630 Circle.java

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.

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
Listing Public Variables and Methods with 'javap'