Java Reference
In-Depth Information
$ javac AllEnv.java
$ java AllEnv
and you will get a long list of properties—in no particular order. They are kept
in a hashtable and thus not sorted. Of course it would be easier to use this list
if they were sorted. Linux to the rescue.
$ java AllEnv | sort
It's often in simple little steps like this that one begins to see the power of
Linux. In Linux, not every desirable feature has to be crammed into every pos-
sible place where it might be used. Instead, features can be written once and
connected to one another as needed. Here what we need is to have the list of
properties sorted. We don't need to worry that our class didn't sort its output.
In Linux we just connect the standard output of the Java program with a sort
utility that Linux provides.
So what are all these properties? Many of them have to do with Java-
related information ( java.version , and so on), but a few are more general.
Those that parallel the typical Linux environment variables are:
file.separator is the file separator (“ / ” on Linux).
path.separator is the path separator (“ : ” on Linux).
line.separator is the line separator (“ \n ” on Linux).
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 environment variables, especially the applica-
tion-specific ones (e.g., CVSROOT ). How would a Java program get at these?
Because of this new, more portable way to describe the environment,
there is no easy way to get at other environment variables. There are a few
approaches, but they are all indirect.
First, you can add to the properties list by defining new properties on the
command line when invoking the program, for example:
$ java -Dkey=value AllEnv
You can list several properties on the line by repeating the -D parameter:
Search WWH ::




Custom Search