Java Reference
In-Depth Information
Chapter 5
Organizing Java files and
other practicalities
5.1 Introduction
In this chapter we look first at several topics related to the organization of Java
files. In fact, a scheme for organizing Java files and classes comes built into the
language. When a class is used, the name of the class includes, either explicitly
or implicitly (via the import directive), its location in a particular package . The
Java package resembles the code libraries of other languages and provides a name
space that successfully avoids name collisions. In practice, a large class library
will contain many packages - the J2SE 1.4 class library contains over 100 separate
packages - arranged in some sensible order. A very small, single-purpose library
might reside entirely in just one package.
In some of the examples in previous chapters the code included the public
modifier. We finally explain in this chapter exactly what that modifier does. It and
the other access modifiers determine what classes, methods and fields can be used
by methods in other classes and subclasses, in the same and in other packages.
Forfaster downloading, you can pack your Java packages, classes, images,
audio files and other program resources into a single file called a JAR (Java
Archive) file. JAR files use the ZIP format and compression system (a variation
of Lempel-Ziv) to hold files and to maintain internally a hierarchical directory
system like that on disk. We show how to create JAR files and how to extract files
from them. We then discuss the pack200 tool in J2SE 5.0 for compressing JAR
files even further.
Other topics presented in this chapter, include the javadoc tool for automatic
documentation of packages and classes, distributing applet files into subdirec-
tories, declaring constants, and coding style conventions. We also look at string
formatting of numerical values with the tools available in J2SE 1.4 and with the
new tools added in J2SE 5.0.
5.2 Class definition files
We first summarize the format of Java files. A file containing a Java class definition
must follow these guidelines:
132
Search WWH ::




Custom Search