java.lang
public final class System extends Object
Since: 1.0
UNKNOWN: still missing 1.4 functionality
Field Summary | |
---|---|
static PrintStream | err
The standard output PrintStream. |
static InputStream | in
The standard InputStream. |
static PrintStream | out
The standard output PrintStream. |
Method Summary | |
---|---|
static void | arraycopy(Object src, int srcStart, Object dest, int destStart, int len)
Copy one array onto another from src[srcStart] ...
|
static String | clearProperty(String key)
Remove a single system property by name. |
static long | currentTimeMillis()
Get the current time, measured in the number of milliseconds from the
beginning of Jan. |
static void | exit(int status)
Terminate the Virtual Machine. |
static void | gc()
Calls the garbage collector. |
static String | getenv(String name)
Gets the value of an environment variable.
|
static Map<String,String> | getenv() Returns an unmodifiable view of the system environment variables. |
static Properties | getProperties()
Get all the system properties at once. |
static String | getProperty(String key)
Get a single system property by name. |
static String | getProperty(String key, String def)
Get a single system property by name. |
static SecurityManager | getSecurityManager()
Get the current SecurityManager. |
static int | identityHashCode(Object o)
Get a hash code computed by the VM for the Object. |
static void | load(String filename)
Load a code file using its explicit system-dependent filename. |
static void | loadLibrary(String libname)
Load a library using its explicit system-dependent filename. |
static String | mapLibraryName(String libname)
Convert a library name to its platform-specific variant.
|
static long | nanoTime() Returns the current value of a nanosecond-precise system timer. |
static void | runFinalization()
Runs object finalization on pending objects. |
static void | runFinalizersOnExit(boolean finalizeOnExit)
Tell the Runtime whether to run finalization before exiting the
JVM. |
static void | setErr(PrintStream err)
Set {@link #err} to a new PrintStream. |
static void | setIn(InputStream in)
Set {@link #in} to a new InputStream. |
static void | setOut(PrintStream out)
Set {@link #out} to a new PrintStream. |
static void | setProperties(Properties properties)
Set all the system properties at once. |
static String | setProperty(String key, String value)
Set a single system property by name. |
static void | setSecurityManager(SecurityManager sm)
Set the current SecurityManager. |
This corresponds to the C stderr and C++ cerr variables, which typically output error messages to the screen, but may be used to pipe output to other processes or files. That should all be transparent to you, however.
This corresponds to the C stdin and C++ cin variables, which typically input from the keyboard, but may be used to pipe input from other processes or files. That should all be transparent to you, however.
This corresponds to the C stdout and C++ cout variables, which typically output normal messages to the screen, but may be used to pipe output to other processes or files. That should all be transparent to you, however.
src[srcStart]
...
src[srcStart+len-1]
to dest[destStart]
...
dest[destStart+len-1]
. First, the arguments are validated:
neither array may be null, they must be of compatible types, and the
start and length must fit within both arrays. Then the copying starts,
and proceeds through increasing slots. If src and dest are the same
array, this will appear to copy the data to a temporary location first.
An ArrayStoreException in the middle of copying will leave earlier
elements copied, but later elements unchanged.
Parameters: src the array to copy elements from srcStart the starting position in src dest the array to copy elements to destStart the starting position in dest len the number of elements to copy
Throws: NullPointerException if src or dest is null ArrayStoreException if src or dest is not an array, if they are not compatible array types, or if an incompatible runtime type is stored in dest IndexOutOfBoundsException if len is negative, or if the start or end copy position in either array is out of bounds
checkPropertyAccess(key, "write")
.
Parameters: key the name of the system property to remove
Returns: the previous value, or null
Throws: SecurityException if permission is denied NullPointerException if key is null IllegalArgumentException if key is ""
Since: 1.5
Returns: the current time
See Also: Date
Runtime.getRuntime().exit(status)
, and never returns.
Obviously, a security check is in order, checkExit
.
Parameters: status the exit status; by convention non-zero is abnormal
Throws: SecurityException if permission is denied
See Also: Runtime
Runtime.getRuntime().gc()
.
See Also: gc
Parameters: name the name of the environment variable
Returns: the string value of the variable or null when the environment variable is not defined.
Throws: NullPointerException SecurityException if permission is denied
Since: 1.5
UNKNOWN: This method was deprecated in some JDK releases, but was restored in 1.5.
Returns an unmodifiable view of the system environment variables. If the underlying system does not support environment variables, an empty map is returned.
The returned map is read-only and does not accept queries using
null keys or values, or those of a type other than String
.
Attempts to modify the map will throw an
UnsupportedOperationException
, while attempts
to pass in a null value will throw a
NullPointerException
. Types other than String
throw a ClassCastException
.
As the returned map is generated using data from the underlying
platform, it may not comply with the equals()
and hashCode()
contracts. It is also likely that
the keys of this map will be case-sensitive.
Use of this method may require a security check for the RuntimePermission "getenv.*".
Returns: a map of the system environment variables.
Throws: SecurityException if the checkPermission method of an installed security manager prevents access to the system environment variables.
Since: 1.5
checkPropertiesAccess
. Note that a security manager may
allow getting a single property, but not the entire group.
The required properties include:
Returns: the system properties, will never be null
Throws: SecurityException if permission is denied
checkPropertyAccess(key)
.
Parameters: key the name of the system property to get
Returns: the property, or null if not found
Throws: SecurityException if permission is denied NullPointerException if key is null IllegalArgumentException if key is ""
checkPropertyAccess(key)
.
Parameters: key the name of the system property to get def the default
Returns: the property, or def if not found
Throws: SecurityException if permission is denied NullPointerException if key is null IllegalArgumentException if key is ""
Returns: the current SecurityManager, or null
Parameters: o the Object to get the hash code for
Returns: the VM-dependent hash code for this Object
Since: 1.1
checkLink
. This just calls
Runtime.getRuntime().load(filename)
.
The library is loaded using the class loader associated with the class associated with the invoking method.
Parameters: filename the code file to load
Throws: SecurityException if permission is denied UnsatisfiedLinkError if the file cannot be loaded
See Also: load
checkLink
. This just calls
Runtime.getRuntime().load(filename)
.
The library is loaded using the class loader associated with the class associated with the invoking method.
Parameters: libname the library file to load
Throws: SecurityException if permission is denied UnsatisfiedLinkError if the file cannot be loaded
See Also: load
Parameters: libname the library name, as used in loadLibrary
Returns: the platform-specific mangling of the name
Since: 1.2
Returns the current value of a nanosecond-precise system timer. The value of the timer is an offset relative to some arbitrary fixed time, which may be in the future (making the value negative). This method is useful for timing events where nanosecond precision is required. This is achieved by calling this method before and after the event, and taking the difference betweent the two times:
long startTime = System.nanoTime();
...
long endTime = System.nanoTime();
long duration = endTime - startTime;
Note that the value is only nanosecond-precise, and not accurate; there is no guarantee that the difference between two values is really a nanosecond. Also, the value is prone to overflow if the offset exceeds 2^63.
Returns: the time of a system timer in nanoseconds.
Since: 1.5
Runtime.getRuntime().runFinalization()
.
See Also: runFinalization
Deprecated: never rely on finalizers to do a clean, thread-safe, mop-up from your code
Tell the Runtime whether to run finalization before exiting the JVM. This is inherently unsafe in multi-threaded applications, since it can force initialization on objects which are still in use by live threads, leading to deadlock; therefore this is disabled by default. There may be a security check,checkExit(0)
. This
calls Runtime.runFinalizersOnExit()
.
Parameters: finalizeOnExit whether to run finalizers on exit
Throws: SecurityException if permission is denied
Since: 1.1
See Also: Runtime
RuntimePermission("setIO")
.
Parameters: err the new PrintStream
Throws: SecurityException if permission is denied
Since: 1.1
RuntimePermission("setIO")
.
Parameters: in the new InputStream
Throws: SecurityException if permission is denied
Since: 1.1
RuntimePermission("setIO")
.
Parameters: out the new PrintStream
Throws: SecurityException if permission is denied
Since: 1.1
checkPropertiesAccess
. Note that a security manager may
allow setting a single property, but not the entire group. An argument
of null resets the properties to the startup default.
Parameters: properties the new set of system properties
Throws: SecurityException if permission is denied
checkPropertyAccess(key, "write")
.
Parameters: key the name of the system property to set value the new value
Returns: the previous value, or null
Throws: SecurityException if permission is denied NullPointerException if key is null IllegalArgumentException if key is ""
Since: 1.2
RuntimePermission("setSecurityManager")
is checked
first. Since this permission is denied by the default security manager,
setting the security manager is often an irreversible action.
Spec Note: Don't ask me, I didn't write it. It looks
pretty vulnerable; whoever gets to the gate first gets to set the policy.
There is probably some way to set the original security manager as a
command line argument to the VM, but I don't know it.
Parameters: sm the new SecurityManager
Throws: SecurityException if permission is denied