THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1

java.vm.version=1.5.0_02-b09
java.vm.vendor=Sun Microsystems Inc.
java.vm.name=Java HotSpot(TM) Client VM
java.specification.version=1.5
java.specification.vendor=Sun Microsystems Inc.
java.specification.name=Java Platform API Specification
java.home=/opt/jdk1.5.0_02/jre
java.class.version=49.0
java.class.path=classes
java.library.path=/opt/jdk1.5.0_02/jre/lib/i386/client:/opt/jdk1.5.0_02/jre/lib/i386:/opt
/jdk1.5.0_02/jre/../lib/i386
java.io.tmpdir=/tmp
java.compiler=
java.ext.dirs=/opt/jdk1.5.0_02/jre/lib/ext
os.name=Linux
os.arch=i386
os.version=2.4.20-31.9smp
file.separator=/
path.separator=:
line.separator=\n
user.name=dholmes
user.home=/home/dholmes
user.dir=/home/dholmes/JPL-4e/src


These properties are defined on all systems, although the values will certainly vary. On any given system
many more properties may be defined. Some of the standard properties are used by classes in the standard
packages. The File class, for example, uses the file.separator property to build up and break down
pathnames. You are also free to use properties. The following method looks for a personal configuration file
in the user's home directory:


public static File personalConfig(String fileName) {
String home = System.getProperty("user.home");
if (home == null)
return null;
else
return new File(home, fileName);
}


The methods of the System class that deal with the system properties are


public static PropertiesgetProperties()

Gets the Properties object that defines all system properties.

public static StringgetProperty(String key)

Returns the value of the system property named in key.

public static StringgetProperty(String key, String
defaultValue)

Returns the value of the system property named in key. If it has no
definition, it returns defaultValue.

public static StringsetProperty(String key, String value)
Free download pdf