Java Fundamental Classes Reference

Previous Chapter 10
Accessing the Environment
Next
 

10.2 System Properties

System properties provide a mechanism for getting information about the environment. You can get the value of a system property by passing its name to the System.getProperty(String) method. This method returns the value of the named property as a String, or it returns null if the property is not defined. Since it is common to assume a default value if a property is not specified, there is also a System.getProperty(String, String) method that takes the name of a property and a default String value to return if the property is not defined.

Table 10.1 lists the standard system properties for a Java environment. Many of these properties are guaranteed to be defined in any Java environment. Note, however, that untrusted applets aren't allowed to access many of these properties.

Table 10.1: Standard System Properties

Property Name

Description

file.encoding

The character encoding for the default locale ( Java 1.1 only)

file.encoding.pkg

The package that contains the converters that handle converting between local encodings and Unicode ( Java 1.1 only)

file.separator

The platform-dependent file separator (e.g., "/" on UNIX, "\" for Windows)

java.class.path

The value of the CLASSPATH environment variable

java.class.version

The version of the Java API

java.compiler

The just-in-time compiler to use, if any. The java interpreter provided with the JDK initializes this property from the environment variable JAVA_COMPILER

java.home

The directory in which Java is installed

java.version

The version of the Java interpreter

java.vendor

A vendor-specific string

java.vendor.url

A vendor URL

line.separator

The platform-dependent line separator (e.g., "\n" on UNIX, "\r\n" for Windows)

os.name

The name of the operating system

os.arch

The system architecture

os.version

The operating system version

path.separator

The platform-dependent path separator (e.g., ":" on UNIX, "," for Windows)

user.dir

The current working directory when the properties were initialized

user.home

The home directory of the current user

user.language

The two-letter language code of the default locale ( Java 1.1 only)

user.name

The username of the current user

user.region

The two-letter country code of the default locale ( Java 1.1 only)

user.timezone

The default time zone ( Java 1.1 only)

The Java API also provides some convenience methods for getting the value of a system property that should be interpreted as a data type other than String:

You can programmatically define properties by calling the System.setProperties() method. The Properties object that you pass to System.setProperties() becomes the new source for all system property values.

If a program is running in a browser or other environment that has a SecurityManager installed, it may be denied any access to system properties.


Previous Home Next
I/O Book Index Environment Variables

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java