Java Reference
In-Depth Information
class. Even if CLine used other classes (it does— String is a class) it doesn't
matter if those other classes have main() methods or not.
4.2.2
Why all the fuss about main() and command-line parameters? Such main()
methods are a handy way to provide unit tests for a class. The tests can be
controlled by the command-line parameters. By testing each class you can re-
duce the time to integrate the parts of an application. Furthermore, a set of unit
tests can be built up (e.g., as shell scripts) to provide automated regression tests
for the entire project. As a more rigorous and systematic approach to unit
testing, we discuss junit in Chapter 13.
Unit Testing Made Easy
T HE System C LASS
4.3
The Java System class provides some of the answers to questions about our
environment. What follows is not an exhaustive discussion of all the methods
in the System class, but only of those areas that touch on our specific focus—
input/output (I/O) and environment variables.
Be aware that all of the methods in the System class are static . There-
fore you never need to (and you can't) call a constructor on System . You just
use the “class name, dot, method name” syntax to call the method (e.g.,
System.getProperties() ). Similarly, the accessible fields in System are all
static , so for some of the I/O-related methods you use the “class name, dot,
field name, dot, method name” syntax (e.g., System.out.println() ). As of
Java 5.0, you can shorten this, by using a static import , that is:
import static java.lang.System.*;
Then in your other references you can leave off System , for example,
getProperties() and out.println() .
4.3.1
Java adopted the UNIX concept of standard I/O (see Section 1.3.1.1). The
Linux file descriptors are available to a running Java program as I/O streams
via the System class. The System class contains three public static fields
Java and Standard I/O
Search WWH ::




Custom Search