Java Reference
In-Depth Information
acter. You'll need to specify a separate path entry for the same directory if you also
want the class files. For example:
javac -classpath /JAVA_DEV/*:/JAVA_DEV
Subdirectories within the class path will not be searched. In order to load files that
are contained within subdirectories, those subdirectories and/or files must be explicitly
listed in the class path. However, Java packages that are equivalent to the subdirectory
structure will be loaded. Therefore, any Java classes that reside within a Java package
that is equivalent to the subdirectory structure will be loaded.
Note It is a good idea to organize your code; it is also good to organize where you
place your code on the computer. A good practice is to place all your Java projects with-
in the same directory; it can become your workspace. Place all the Java libraries that are
contained in JAR files into the same directory for easier management.
1-11. Reading Environment Variables
Problem
The application you are developing needs to make use of some environment variables.
You want to read the values that have been set from the operating-system level.
Solution
Make use of the Java System class to retrieve any environment variable values. The
System class has a method called getenv() , which accepts a String argument
corresponding to the name of a system environment variable. The method will then re-
turn the value of the given variable. If no matching environment variable exists, a
NULL value will be returned. Listing 1-9 provides an example. The class
ReadOneEnvVariable accepts an environment variable name as a parameter, and
displays the variable's value that has been set at the operating-system level.
Listing 1-9 . Reading an Environment Variable's Value
 
 
Search WWH ::




Custom Search