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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.3 The System Class107$ javac AllEnv.java$ java AllEnvand you will get a l<strong>on</strong>g list of properties—in no particular order. They are keptin a hashtable and thus not sorted. Of course it would be easier to use this listif they were sorted. <strong>Linux</strong> to the rescue.$ java AllEnv | sortIt’s often in simple little steps like this that <strong>on</strong>e begins to see the power of<strong>Linux</strong>. In <strong>Linux</strong>, not every desirable feature has to be crammed into every possibleplace where it might be used. Instead, features can be written <strong>on</strong>ce andc<strong>on</strong>nected to <strong>on</strong>e another as needed. Here what we need is to have the list ofproperties sorted. We d<strong>on</strong>’t need to worry that our class didn’t sort its output.In <strong>Linux</strong> we just c<strong>on</strong>nect the standard output of the Java program with a sortutility that <strong>Linux</strong> provides.So what are all these properties? Many of them have to do with Javarelatedinformati<strong>on</strong> (java.versi<strong>on</strong>, and so <strong>on</strong>), but a few are more general.Those that parallel the typical <strong>Linux</strong> envir<strong>on</strong>ment variables are:• file.separator is the file separator (“/” <strong>on</strong> <strong>Linux</strong>).• path.separator is the path separator (“:” <strong>on</strong> <strong>Linux</strong>).• line.separator is the line separator (“\n” <strong>on</strong> <strong>Linux</strong>).• user.name is the user’s account name.• user.home is the user’s home directory.• user.dir is the user’s current working directory.But that leaves out so many envir<strong>on</strong>ment variables, especially the applicati<strong>on</strong>-specific<strong>on</strong>es (e.g., CVSROOT). How would a Java program get at these?Because of this new, more portable way to describe the envir<strong>on</strong>ment,there is no easy way to get at other envir<strong>on</strong>ment variables. There are a fewapproaches, but they are all indirect.First, you can add to the properties list by defining new properties <strong>on</strong> thecommand line when invoking the program, for example:$ java -Dkey=value AllEnvYou can list several properties <strong>on</strong> the line by repeating the -D parameter:

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

Saved successfully!

Ooh no, something went wrong!