Often, a program requires access to system resources such as properties, standard input and output streams, or the current time:
System class include:
standard input, output, and error streams;
system properties;
garbage collection;
loading dynamic libraries;
miscellany, including copying arrays, getting the current time, exiting the runtime environment, and using the security manager.
![]() | 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
Key | Meaning | Applet Access |
---|---|---|
"file.separator" | File separator (e.g., "/") | yes |
"java.class.path" | Java classpath | no |
"java.class.version" | Java class version number | yes |
"java.home" | Java installation directory | no |
"java.vendor" | Java vendor-specific string | yes |
"java.vendor.url" | Java vendor URL | yes |
"java.version" | Java version number | yes |
"line.separator" | Line separator | yes |
"os.arch" | Operating system architecture | yes |
"os.name" | Operating system name | yes |
"path.separator" | Path separator (e.g., ":") | yes |
"user.dir" | User's current working directory | no |
"user.home" | User home directory | no |
"user.name" | User account name | no |
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.
The oval labelled Runtime in the diagram represents the current runtime environment and is an instance of the Runtime Class.
![]() | Note |
---|---|
Messaging the Runtime object directly compromises your ability to run your program on different systems. You should do this only in special situation. |
Copyright © 1998-2009 Dilvan Moreira