Java Tools Tutorials - Herong's Tutorial Notes - Version 5.30, by Dr. Herong Yang

Looking Up Method Signature with 'javap' Command

This section provides a tutorial example of how to lookup method signatures in a class file or JAR file with the 'javap' command.

"javap" can also be used as a handy tool to look up method signatures while you are writing Java programs.

For example, if you are coding a Java program, and you need to convert a byte array into a character string, but you don't remember which method in the String class to use, and how many arguments are needed for that method. If you are using a good Java IDE, it will help you with a list of public methods and their signatures.

But what can you do, if you are using a simple text editor, not a smart Java IDE? You can use the "javap" command as a handy tool to look up method signatures. The following tutorial example shows you how to find the method to convert a byte array into a character string:

C:\herong>javap java.lang.String | find "byte"

    public java.lang.String(byte[], int, int, int);
    public java.lang.String(byte[], int);
    public java.lang.String(byte[], int, int, java.lang.String)
    public java.lang.String(byte[], java.lang.String)
    public java.lang.String(byte[], int, int);
    public java.lang.String(byte[]);
    public void getBytes(int, int, byte[], int);
    public byte[] getBytes(java.lang.String)
    public byte[] getBytes();

What can you learn from this tutorial example:

  • "java.lang.String" is the fully qualified class name for the String class.
  • The bytecode of "java.lang.String" is inside the JDK JAR file: \progra~1\java\jdk*\jre\lib\rt.jar. since "rt.jar" is the default JAR file, you don't need to specify it with the "-classpath" option.
  • I used the Windows "find" command (similar to the Unix "grep" command) to select method signatures that contains the word "byte" to reduce the amount of output lines.
  • Based on the output, the simplest method is the constructor "String(byte[])", which converts all bytes in the specified byte array into a string using the default character encoding.

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


 PDF Printing Version

Looking Up Method Signature with 'javap' Command - Updated in 2014, by Dr. Herong Yang