13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

102Chapter 4Where Am I? Executi<strong>on</strong> C<strong>on</strong>textclass. Even if CLine used other classes (it does—String is a class) it doesn’tmatter if those other classes have main() methods or not.4.2.2 Unit Testing Made EasyWhy 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 bec<strong>on</strong>trolled by the command-line parameters. By testing each class you can reducethe time to integrate the parts of an applicati<strong>on</strong>. Furthermore, a set of unittests can be built up (e.g., as shell scripts) to provide automated regressi<strong>on</strong> testsfor the entire project. As a more rigorous and systematic approach to unittesting, we discuss junit in Chapter 13.4.3THE System CLASSThe Java System class provides some of the answers to questi<strong>on</strong>s about ourenvir<strong>on</strong>ment. What follows is not an exhaustive discussi<strong>on</strong> of all the methodsin the System class, but <strong>on</strong>ly of those areas that touch <strong>on</strong> our specific focus—input/output (I/O) and envir<strong>on</strong>ment variables.Be aware that all of the methods in the System class are static. Thereforeyou never need to (and you can’t) call a c<strong>on</strong>structor <strong>on</strong> System. You justuse the “class name, dot, method name” syntax to call the method (e.g.,System.getProperties()). Similarly, the accessible fields in System are allstatic, 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 ofJava 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 and Standard I/OJava adopted the UNIX c<strong>on</strong>cept of standard I/O (see Secti<strong>on</strong> 1.3.1.1). The<strong>Linux</strong> file descriptors are available to a running Java program as I/O streamsvia the System class. The System class c<strong>on</strong>tains three public static fields

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!