Java Reference
In-Depth Information
figure 3.15
Packages defined in
this text
Package
Use
weiss.util
A reimplementation of a subset of the java.util package
containing various data structures.
weiss.nonstandard
Various data structures, in a simplified form, using nonstand-
ard conventions that are different from java.util .
Programmers who made heavy use of the math library had long hoped for
a generalization of the import directive that would allow methods such as
sin , cos , tan to be used rather than the more verbose Math.sin , Math.cos ,
Math.tan . In Java 5, this feature was added to the language via the static
import directive. The static import directive allows static members (meth-
ods and fields) to be accessed without explicitly providing the class name.
The static import directive has two forms: the single member import, and
the wildcard import. Thus,
import static java.lang.Math.*;
import static java.lang.Integer.MAX_VALUE;
allows the programmer to write max instead of Math.max , PI instead of Math.PI ,
and MAX_VALUE instead of Integer.MAX_VALUE .
3.8.2 the package statement
To indicate that a class is part of a package, we must do two things. First, we
must include the package statement as the first line, prior to the class defini-
tion. Second, we must place the code in an appropriate subdirectory.
In this text, we use the two packages shown in Figure 3.15. Other pro-
grams, including test programs and the application programs in Part Three of
this topic, are stand-alone classes and not part of a package.
The package state-
ment indicates that
a class is part of a
package. It must
precede the class
definition.
1 package weiss.math;
2
3 import java.math.BigInteger;
4
5 public class BigRational
6 {
7 /* Entire class shown in online code */
8 }
figure 3.16
Moving the
BigRational class to
package weiss.math.
 
 
Search WWH ::




Custom Search