The javad program reads a Java class file and writes out a Java like source representation of the class that generated the file.

See:
          Description

Packages
attr The attr package contains the class hierarcy that is used to represent the Java Virtual Machine class file attributes.
classfile This package contains Java code to read and display the contents of a Java Virtual Machine class file.
jconst The jconst package contains the class hierarchy that represents the Java class file constants and other values stored in the class file constant pool.
util The util package contains the various utility classes that support the javad java class file disassembly program.

 

The javad program reads a Java class file and writes out a Java like source representation of the class that generated the file. This kind of program is commonly called a Java class file disassembler.

Regardless of the number of classes in a source file, Java compilers that follow Sun's Java scheme will compile one class per file. This program reads the compiled class and dumps it in a readable form, akin to Java source.

Usage

java javad.main classfile-list

For example: java javad.main one.class two.class three.class

Notes

Why was this program written?

I wanted to understand the Java class file format. This was critical for my work on a Java compiler, since a Java compiler must be able to read class symbol information from the .class file.

Why would you be interested in this program?

If you are working on the Java class file format for a Java Virtual Machine or other system support for Java execution, an understanding of the Java class file format is important. The Java code for javad is commented extensively and in some places explains features that are poorly documented in the Java Virtual Machine Specification (by Lindholm and Yellin, second edition, Addison Wesley, 1999).

How do you regenerate the documentation using javadoc?

I find javadoc rather obscure and hard to use. But I really like the idea of documentation that is automaticly generated from the Java source. The documentation for the javad program was created using the source line command

javadoc -author -overview overview.html -private -use -d doc attr classfile jconst util javad.java

Here doc is the directory containing the documentaton. Note that the packages are listed before the javad.java file.

Prior Art

A number of Java class file disassemblers have been written. One of these is shipped in binary form with the Sun Java release (javap). There are several class file disassemblers available in source form. These include:

Disassemblers and decompilers

As any Java programmer knows, Java does not use header files to define external classes (e.g., a class that is not in the current file). Information about the structure of a class can be obtained from a .class file. As the javad and the other class file disassemblers show, the much of the original source for the class definition can be recovered from the class file.

Compared to machine code (e.g., x86, powerPC, SPARC), Java byte codes are very high level. A clever piece of software can recover something close to the original source code for the methods. These programs are referred to as decompilers. For those who want to keep their source code secret there are Java code obfuscators.

A list of Java disassemblers and decompilers is published on Marc Meurrens home page.

This page mentions that Hanpeter van Vliet wrote a Java decompiler, named Mocha. Apparently the program does a good job of decompiling Java class files. When it appeared the first response, presumably of some United States citizens, was to threaten to sue. Sanity seems to have asserted itself and no one sued. But it spurred the development of "obfuscators", including van Vliet's own "Crema". A copy of van Vliet's "manifesto" can be found here.

According to this web page, van Vliet died of cancer on December 31, 1996 at age 34, not long after finishing Mocha. The current Mocha release can also be found on Eric Smith's web page

It is interesting to note that at one point Borland/Imprise sent e-mail to Eric Smith claiming ownership of Mocha. The despicable way that some companies treat free software is the motivation for the Bear Products International source license agreement used for Javad.

The European KOPI project has created a Java source to byte code compiler. KOPI also includes byte code assemblers and a class file disassembler. The KOPI project can be found here

Marco Schmidt has published a list of Java compilers and Java VMs. This list can be found here

For copyright and usage permissions for the javad program, see the copyright

Author:
Ian Kaplan