Java Reference
In-Depth Information
The set [^A-Za-z] denotes any characters that are not in the ranges A to Z and
a to z . This works much better, and it shows only lines that contain actual
numbers.
For more information on regular expressions, consult one of the many tutorials
on the Internet (such as [ 2 ]).
A DVANCED T OPIC 8.4: Static Imports
Starting with Java version 5.0, there is a variant of the import directive that
lets you use static methods and fields without class prefixes. For example,
import static java.lang.System.*;
import static java.lang.Math.*;
public class RootTester
{
public static void main(String[] args)
{
double r = sqrt(PI) // Instead of Math. sqrt
(Math. PI)
out.println(r); // Instead of System.out
}
}
Static imports can make programs easier to read, particularly if they use many
mathematical functions.
8.9 Packages
8.9.1 Organizing Related Classes into Packages
A Java program consists of a collection of classes. So far, most of your programs
have consisted of a small number of classes. As programs get larger, however,
simply distributing the classes over multiple files isn't enough. An additional
structuring mechanism is needed. In Java, packages provide this structuring
mechanism. A Java package is a set of related classes. For example, the Java library
consists of dozens of packages, some of which are listed in Table 1 .
Search WWH ::




Custom Search