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) 2015, HerongYang.com, All Rights Reserved.
 */
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.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

'javap' - The Java Class File Disassembler

 '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

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version