2. System Class

Often, a program requires access to system resources such as properties, standard input and output streams, or the current time:

Figure 5.3. System Class

System Class

System class include:

[Note]Note

All of System's methods and variables are class methods and class variables.

A set of properties - key/value pairs - that define traits or attributes of the current working environment.

Table 5.1. System Properties

KeyMeaningApplet Access
"file.separator"File separator (e.g., "/")yes
"java.class.path"Java classpathno
"java.class.version"Java class version numberyes
"java.home"Java installation directoryno
"java.vendor"Java vendor-specific stringyes
"java.vendor.url"Java vendor URLyes
"java.version"Java version numberyes
"line.separator"Line separatoryes
"os.arch"Operating system architectureyes
"os.name"Operating system nameyes
"path.separator"Path separator (e.g., ":")yes
"user.dir"User's current working directoryno
"user.home"User home directoryno
"user.name"User account nameno

Audio in Portuguese

2.2. Reading/Writing System Properties

System.getProperty("path.separator");

System.getProperty("subliminal.message", "Buy Java Now!");

The getProperties() returns a Properties object.

The setProperties() method: takes a Properties object.

System.runFinalization();

This method calls the finalize() methods on all objects that are waiting to be garbage collected.

System.gc();

It asks the garbage collector to run at any time by calling System's gc() method.

It bypasses the system-independent interface of the System class and use system resources directly from the runtime environment.

Figure 5.4. Runtime Object

Runtime Object

The oval labelled Runtime in the diagram represents the current runtime environment and is an instance of the Runtime Class.

[Note]Note

Messaging the Runtime object directly compromises your ability to run your program on different systems. You should do this only in special situation.

Audio in Portuguese