Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.lang

Class System

java.lang.Object
|
+--java.lang.System


public final class System

extends Object

System represents system-wide resources; things that represent the general environment. As such, all methods are static.

Since:Authors:

Field Summary

static java.io.PrintStreamerr

The standard output PrintStream.
static java.io.InputStreamin

The standard InputStream.
static java.io.PrintStreamout

The standard output PrintStream.

Method Summary

static voidarraycopy(java.lang.Object src, int srcStart, java.lang.Object dest, int destStart, int len)

Copy one array onto another from src[srcStart] ...
static longcurrentTimeMillis()

Get the current time, measured in the number of milliseconds from the beginning of Jan.
static voidexit(int status)

Terminate the Virtual Machine.
static voidgc()

Calls the garbage collector.
static java.util.PropertiesgetProperties()

Get all the system properties at once.
static java.lang.StringgetProperty(java.lang.String key)

Get a single system property by name.
static java.lang.StringgetProperty(java.lang.String key, java.lang.String def)

Get a single system property by name.
static java.lang.SecurityManagergetSecurityManager()

Get the current SecurityManager.
static java.lang.Stringgetenv(java.lang.String name)

This used to get an environment variable, but following Sun's lead, it now throws an Error.
static intidentityHashCode(java.lang.Object o)

Get a hash code computed by the VM for the Object.
static voidload(java.lang.String filename)

Load a code file using its explicit system-dependent filename.
static voidloadLibrary(java.lang.String libname)

Load a library using its explicit system-dependent filename.
static java.lang.StringmapLibraryName(java.lang.String libname)

Convert a library name to its platform-specific variant.
static voidrunFinalization()

Runs object finalization on pending objects.
static voidrunFinalizersOnExit(boolean finalizeOnExit)

Tell the Runtime whether to run finalization before exiting the JVM.
static voidsetErr(java.io.PrintStream err)

Set #err to a new PrintStream.
static voidsetIn(java.io.InputStream in)

Set #in to a new InputStream.
static voidsetOut(java.io.PrintStream out)

Set #out to a new PrintStream.
static voidsetProperties(java.util.Properties properties)

Set all the system properties at once.
static java.lang.StringsetProperty(java.lang.String key, java.lang.String value)

Set a single system property by name.
static synchronized voidsetSecurityManager(java.lang.SecurityManager sm)

Set the current SecurityManager.

Field Details

err

public static final PrintStream err

The standard output PrintStream. This is assigned at startup and starts its life perfectly valid. Although it is marked final, you can change it using #setOut(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.


in

public static final InputStream in

The standard InputStream. This is assigned at startup and starts its life perfectly valid. Although it is marked final, you can change it using #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.


out

public static final PrintStream out

The standard output PrintStream. This is assigned at startup and starts its life perfectly valid. Although it is marked final, you can change it using #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.


Method Details

arraycopy

public static void arraycopy(java.lang.Object src, int srcStart, java.lang.Object dest, int destStart, int len)

Copy one array onto another from 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:

Throws:


currentTimeMillis

public static long currentTimeMillis()

Get the current time, measured in the number of milliseconds from the beginning of Jan. 1, 1970. This is gathered from the system clock, with any attendant incorrectness (it may be timezone dependent).

Returns:

See Also:


exit

public static void exit(int status)

Terminate the Virtual Machine. This just calls Runtime.getRuntime().exit(status), and never returns. Obviously, a security check is in order, checkExit.

Parameters:

Throws:

See Also:


gc

public static void gc()

Calls the garbage collector. This is only a hint, and it is up to the implementation what this hint suggests, but it usually causes a best-effort attempt to reclaim unused memory from discarded objects. This calls Runtime.getRuntime().gc().

See Also:


getProperties

public static Properties getProperties()

Get all the system properties at once. A security check may be performed, checkPropertiesAccess. Note that a security manager may allow getting a single property, but not the entire group.

The required properties include:

java.version
Java version number
java.vendor
Java vendor specific string
java.vendor.url
Java vendor URL
java.home
Java installation directory
java.vm.specification.version
VM Spec version
java.vm.specification.vendor
VM Spec vendor
java.vm.specification.name
VM Spec name
java.vm.version
VM implementation version
java.vm.vendor
VM implementation vendor
java.vm.name
VM implementation name
java.specification.version
Java Runtime Environment version
java.specification.vendor
Java Runtime Environment vendor
java.specification.name
Java Runtime Environment name
java.class.version
Java class version number
java.class.path
Java classpath
java.library.path
Path for finding Java libraries
java.io.tmpdir
Default temp file path
java.compiler
Name of JIT to use
java.ext.dirs
Java extension path
os.name
Operating System Name
os.arch
Operating System Architecture
os.version
Operating System Version
file.separator
File separator ("/" on Unix)
path.separator
Path separator (":" on Unix)
line.separator
Line separator ("\n" on Unix)
user.name
User account name
user.home
User home directory
user.dir
User's current working directory
In addition, gnu defines several other properties, where ? stands for each character in '0' through '9':
gnu.classpath.home
Path to the classpath libraries.
gnu.classpath.version
Version of the classpath libraries.
gnu.classpath.vm.shortname
Succinct version of the VM name; used for finding property files in file system
gnu.classpath.home.url
Base URL; used for finding property files in file system
gnu.cpu.endian
big or little
gnu.java.io.encoding_scheme_alias.ISO-8859-?
8859_?
gnu.java.io.encoding_scheme_alias.iso-8859-?
8859_?
gnu.java.io.encoding_scheme_alias.iso8859_?
8859_?
gnu.java.io.encoding_scheme_alias.iso-latin-_?
8859_?
gnu.java.io.encoding_scheme_alias.latin?
8859_?
gnu.java.io.encoding_scheme_alias.UTF-8
UTF8
gnu.java.io.encoding_scheme_alias.utf-8
UTF8

Returns:

Throws:


getProperty

public static String getProperty(java.lang.String key)

Get a single system property by name. A security check may be performed, checkPropertyAccess(key).

Parameters:

Returns:

Throws:


getProperty

public static String getProperty(java.lang.String key, java.lang.String def)

Get a single system property by name. A security check may be performed, checkPropertyAccess(key).

Parameters:

Returns:

Throws:


getSecurityManager

public static SecurityManager getSecurityManager()

Get the current SecurityManager. If the SecurityManager has not been set yet, then this method returns null.

Returns:


getenv

public static String getenv(java.lang.String name)

This used to get an environment variable, but following Sun's lead, it now throws an Error. Use getProperty instead.

Parameters:

Returns:

Throws:


identityHashCode

public static int identityHashCode(java.lang.Object o)

Get a hash code computed by the VM for the Object. This hash code will be the same as Object's hashCode() method. It is usually some convolution of the pointer to the Object internal to the VM. It follows standard hash code rules, in that it will remain the same for a given Object for the lifetime of that Object.

Since:Parameters:

Returns:


load

public static void load(java.lang.String filename)

Load a code file using its explicit system-dependent filename. A security check may be performed, checkLink. This just calls Runtime.getRuntime().load(filename).

Parameters:

Throws:

See Also:


loadLibrary

public static void loadLibrary(java.lang.String libname)

Load a library using its explicit system-dependent filename. A security check may be performed, checkLink. This just calls Runtime.getRuntime().load(filename).

Parameters:

Throws:

See Also:


mapLibraryName

public static String mapLibraryName(java.lang.String libname)

Convert a library name to its platform-specific variant. * @param libname the library name, as used in loadLibrary

Since:Parameters:

Returns:


runFinalization

public static void runFinalization()

Runs object finalization on pending objects. This is only a hint, and it is up to the implementation what this hint suggests, but it usually causes a best-effort attempt to run finalizers on all objects ready to be reclaimed. This calls Runtime.getRuntime().runFinalization().

See Also:


runFinalizersOnExit

public static void runFinalizersOnExit(boolean finalizeOnExit)

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.getRuntime().runFinalizersOnExit().

Since:Parameters:

Throws:

See Also:


setErr

public static void setErr(java.io.PrintStream err)

Set #err to a new PrintStream. This uses some VM magic to change a "final" variable, so naturally there is a security check, RuntimePermission("setIO").

Since:Parameters:

Throws:


setIn

public static void setIn(java.io.InputStream in)

Set #in to a new InputStream. This uses some VM magic to change a "final" variable, so naturally there is a security check, RuntimePermission("setIO").

Since:Parameters:

Throws:


setOut

public static void setOut(java.io.PrintStream out)

Set #out to a new PrintStream. This uses some VM magic to change a "final" variable, so naturally there is a security check, RuntimePermission("setIO").

Since:Parameters:

Throws:


setProperties

public static void setProperties(java.util.Properties properties)

Set all the system properties at once. A security check may be performed, 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:

Throws:


setProperty

public static String setProperty(java.lang.String key, java.lang.String value)

Set a single system property by name. A security check may be performed, checkPropertyAccess(key, "write").

Since:Parameters:

Returns:

Throws:


setSecurityManager

public static synchronized void setSecurityManager(java.lang.SecurityManager sm)

Set the current SecurityManager. If a security manager already exists, then 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:

Throws: