Modifier and Type | Field and Description |
---|---|
static PrintStream |
err
The standard output PrintStream.
|
static InputStream |
in
The standard InputStream.
|
static PrintStream |
out
The standard output PrintStream.
|
Modifier and Type | Method and Description |
---|---|
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. 1, 1970.
|
static void |
exit(int status)
Terminate the Virtual Machine.
|
static void |
gc()
Calls the garbage collector.
|
static Map<String,String> |
getenv()
Returns an unmodifiable view of the system environment variables.
|
static String |
getenv(String name)
Gets the value of an environment variable.
|
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 Channel |
inheritedChannel()
Returns the inherited channel of the VM.
|
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()
Get the current time, measured in nanoseconds.
|
static void |
runFinalization()
Runs object finalization on pending objects.
|
static void |
runFinalizersOnExit(boolean finalizeOnExit)
Deprecated.
never rely on finalizers to do a clean, thread-safe,
mop-up from your code
|
static void |
setErr(PrintStream err)
Set
err to a new PrintStream. |
static void |
setIn(InputStream in)
Set
in to a new InputStream. |
static void |
setOut(PrintStream out)
Set
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.
|
public static final InputStream in
setIn(InputStream)
through some hefty VM magic.
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.
public static final PrintStream out
setOut(PrintStream)
through some hefty VM magic.
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.
public static final PrintStream err
setErr(PrintStream)
through some hefty VM magic.
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.
public static void setIn(InputStream in)
in
to a new InputStream. This uses some VM magic to change
a "final" variable, so naturally there is a security check,
RuntimePermission("setIO")
.in
- the new InputStreamSecurityException
- if permission is deniedpublic static void setOut(PrintStream out)
out
to a new PrintStream. This uses some VM magic to change
a "final" variable, so naturally there is a security check,
RuntimePermission("setIO")
.out
- the new PrintStreamSecurityException
- if permission is deniedpublic static void setErr(PrintStream err)
err
to a new PrintStream. This uses some VM magic to change
a "final" variable, so naturally there is a security check,
RuntimePermission("setIO")
.err
- the new PrintStreamSecurityException
- if permission is deniedpublic static void setSecurityManager(SecurityManager sm)
RuntimePermission("setSecurityManager")
is checked
first. Since this permission is denied by the default security manager,
setting the security manager is often an irreversible action.sm
- the new SecurityManagerSecurityException
- if permission is deniedpublic static SecurityManager getSecurityManager()
public static long currentTimeMillis()
Date
public static long nanoTime()
public static void arraycopy(Object src, int srcStart, Object dest, int destStart, int len)
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.src
- the array to copy elements fromsrcStart
- the starting position in srcdest
- the array to copy elements todestStart
- the starting position in destlen
- the number of elements to copyNullPointerException
- if src or dest is nullArrayStoreException
- if src or dest is not an array, if they are
not compatible array types, or if an incompatible runtime type
is stored in destIndexOutOfBoundsException
- if len is negative, or if the start or
end copy position in either array is out of boundspublic static int identityHashCode(Object o)
o
- the Object to get the hash code forpublic static Properties getProperties()
checkPropertiesAccess
. Note that a security manager may
allow getting a single property, but not the entire group.
The required properties include:
SecurityException
- if permission is deniedpublic static void setProperties(Properties properties)
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.properties
- the new set of system propertiesSecurityException
- if permission is deniedpublic static String getProperty(String key)
checkPropertyAccess(key)
.key
- the name of the system property to getSecurityException
- if permission is deniedNullPointerException
- if key is nullIllegalArgumentException
- if key is ""public static String getProperty(String key, String def)
checkPropertyAccess(key)
.key
- the name of the system property to getdef
- the defaultSecurityException
- if permission is deniedNullPointerException
- if key is nullIllegalArgumentException
- if key is ""public static String setProperty(String key, String value)
checkPropertyAccess(key, "write")
.key
- the name of the system property to setvalue
- the new valueSecurityException
- if permission is deniedNullPointerException
- if key is nullIllegalArgumentException
- if key is ""public static String clearProperty(String key)
checkPropertyAccess(key, "write")
.key
- the name of the system property to removeSecurityException
- if permission is deniedNullPointerException
- if key is nullIllegalArgumentException
- if key is ""public static String getenv(String name)
name
- the name of the environment variableNullPointerException
SecurityException
- if permission is deniedpublic static Map<String,String> getenv()
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.*".
SecurityException
- if the checkPermission method of
an installed security manager prevents access to
the system environment variables.public static void exit(int status)
Runtime.getRuntime().exit(status)
, and never returns.
Obviously, a security check is in order, checkExit
.status
- the exit status; by convention non-zero is abnormalSecurityException
- if permission is deniedRuntime.exit(int)
public static void gc()
Runtime.getRuntime().gc()
.Runtime.gc()
public static void runFinalization()
Runtime.getRuntime().runFinalization()
.Runtime.runFinalization()
public static void runFinalizersOnExit(boolean finalizeOnExit)
checkExit(0)
. This
calls Runtime.getRuntime().runFinalizersOnExit()
.finalizeOnExit
- whether to run finalizers on exitSecurityException
- if permission is deniedRuntime#runFinalizersOnExit()
public static void load(String filename)
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.
filename
- the code file to loadSecurityException
- if permission is deniedUnsatisfiedLinkError
- if the file cannot be loadedRuntime.load(String)
public static void loadLibrary(String libname)
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.
libname
- the library file to loadSecurityException
- if permission is deniedUnsatisfiedLinkError
- if the file cannot be loadedRuntime.load(String)
public static String mapLibraryName(String libname)
libname
- the library name, as used in loadLibrary
public static Channel inheritedChannel() throws IOException
SelectorProvider
.IOException
- If an I/O error occursSecurityException
- If an installed security manager denies access
to RuntimePermission("inheritedChannel")