Java Reference
In-Depth Information
5.10
R ETURN TO THE S OURCE :T HE J AVA D ECOMPILER
Java includes a decompiler of sorts called javap . It is sometimes referred to as
the “class file disassembler.” We titled this section “Return to the Source,” but
it is a bit misleading; javap simply provides a way to examine the members and
methods of a compiled Java class 24 even when you do not have its source code.
The javap command takes the same access-modifier command-line argu-
ments as javadoc ( -public , -protected , -package , -private ) to determine
which attributes and methods are to be reported. An additional switch, -c ,
causes the bytecodes of methods to be reported. For details, see Sun's documen-
tation for javap . 25
Example 5.19 shows what you get if you run javap -c on our FetchURL
example.
5.11
B UNDLING A J AVA P ROGRAM : P UT I TINA JAR
Distributing a Java application can be a pain. All but the simplest of applica-
tions will have many public classes—and since there can only be one public
Java class per source file, each Java source file becomes a class file, and the ele-
ments of a package name become directory nodes in the path to the class, you
end up with a fairly complex collection of directories and files. Wouldn't it be
nice to be able to roll the whole mess up into a single binary file for
distribution?
Well, you can. The tool to do the job is called jar , which stands for Java
ARchive. 26 The files produced by this utility are called JAR files . The JAR for-
mat is the common DOS/Windows ZIP file format, with a few special files to
support some special features we will explain as they come up.
24. In Chapter 7 we will introduce gcj , the GNU Compiler for Java, which compiles Java to
native machine code. javap is useless with such a file. It deals only with JVM bytecodes as
documented in Sun's JVM Specification.
25. http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javap.html
26. An abbreviation made up of syllables from words instead of just initials is called a
portmanteau . The US Navy is particularly keen on them, using terms like COMSURPAC
(Commander, Surface Fleet, Pacific), COMSUBLANT (Commander, Submarine Fleet,
Atlantic), and so forth. There. Now you can't claim you didn't learn anything from this topic.
Search WWH ::




Custom Search