java.lang
Class System
System represents system-wide resources; things that represent the
general environment. As such, all methods are static.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
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
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.
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.
String> getenv
public static MapString> 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.*".
- a map of the system environment variables.
SecurityException
- if the checkPermission method of
an installed security manager prevents access to
the system environment variables.
arraycopy
public static void arraycopy(Object src,
int srcStart,
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.
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 copy
clearProperty
public static String clearProperty(String key)
Remove a single system property by name. A security check may be
performed, checkPropertyAccess(key, "write")
.
key
- the name of the system property to remove
- the previous value, or null
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).
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
.
status
- the exit status; by convention non-zero is abnormal
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()
.
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:
In addition, gnu defines several other properties, where ? stands for
each character in '0' through '9':
- the system properties, will never be null
getProperty
public static String getProperty(String key)
Get a single system property by name. A security check may be performed,
checkPropertyAccess(key)
.
key
- the name of the system property to get
- the property, or null if not found
getProperty
public static String getProperty(String key,
String def)
Get a single system property by name. A security check may be performed,
checkPropertyAccess(key)
.
key
- the name of the system property to getdef
- the default
- the property, or def if not found
getSecurityManager
public static SecurityManager getSecurityManager()
Get the current SecurityManager. If the SecurityManager has not been
set yet, then this method returns null.
- the current SecurityManager, or null
getenv
public static String getenv(String name)
Gets the value of an environment variable.
name
- the name of the environment variable
- the string value of the variable or null when the
environment variable is not defined.
identityHashCode
public static int identityHashCode(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.
o
- the Object to get the hash code for
- the VM-dependent hash code for this Object
load
public static void load(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)
.
The library is loaded using the class loader associated with the
class associated with the invoking method.
filename
- the code file to load
loadLibrary
public static void loadLibrary(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)
.
The library is loaded using the class loader associated with the
class associated with the invoking method.
libname
- the library file to load
mapLibraryName
public static String mapLibraryName(String libname)
Convert a library name to its platform-specific variant.
libname
- the library name, as used in loadLibrary
- the platform-specific mangling of the name
nanoTime
public static long nanoTime()
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();
... event code ...
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.
- the time of a system timer in nanoseconds.
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()
.
runFinalizersOnExit
public static void runFinalizersOnExit(boolean finalizeOnExit)
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()
.
finalizeOnExit
- whether to run finalizers on exit
setErr
public static void setErr(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")
.
err
- the new PrintStream
setIn
public static void setIn(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")
.
setOut
public static void setOut(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")
.
out
- the new PrintStream
setProperties
public static void setProperties(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.
properties
- the new set of system properties
setProperty
public static String setProperty(String key,
String value)
Set a single system property by name. A security check may be performed,
checkPropertyAccess(key, "write")
.
key
- the name of the system property to setvalue
- the new value
- the previous value, or null
setSecurityManager
public static void setSecurityManager(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.
sm
- the new SecurityManager
System.java -- useful methods to interface with the system
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.