public final class System extends Object
Modifier and Type | Field and Description |
---|---|
static PrintStream |
err
The "standard" error output stream.
|
static InputStream |
in
The "standard" input stream.
|
static PrintStream |
out
The "standard" output stream.
|
Modifier and Type | Method and Description |
---|---|
static void |
arraycopy(Object src,
int sp,
Object dst,
int dp,
int length)
arraycopy copies element from one array to another array.
|
static String |
clearProperty(String key)
clearProperty removes a given property
|
static Console |
console()
Returns the unique
Console object associated
with the current Java virtual machine, if any. |
static long |
currentTimeMillis()
setProp(b75b89c0,b75b89a0)
currentTimeMillis returns the current time measured from 00:00:00
1 Jan 1970 in milliseconds.
|
static void |
exit(int status)
Terminates the currently running Java Virtual Machine.
|
static void |
gc()
gc indicates to the VM that it may be a good time to run the
garbage collector.
|
static Map<String,String> |
getenv()
Returns an unmodifiable string map view of the current system environment.
|
static String |
getenv(String name)
Gets the value of the specified environment variable.
|
static Properties |
getProperties()
Determines the current system properties.
|
static String |
getProperty(String key)
getProperty returns the value of a given property.
|
static String |
getProperty(String key,
String def)
getProperty returns the value of a given property, or a default
value if the property is not set.
|
static SecurityManager |
getSecurityManager()
getSecurityManager returns the currently installed security
manager.
|
static int |
identityHashCode(Object x)
identityHashCode returns the same hash code that is returned by
the not-overwritten Object.hashCode() function.
|
static Channel |
inheritedChannel()
Returns the channel inherited from the entity that created this
Java virtual machine.
|
static String |
lineSeparator()
Returns the system-dependent line separator string.
|
static void |
load(String filename)
load a library or system file.
|
static void |
loadLibrary(String libname)
loadLibrary loads a system library with the given name into the
system.
|
static String |
mapLibraryName(String libname)
mapLibraryName maps a library name to the corresponding
platform-specific native library name
|
static long |
nanoTime()
nanoTime returns a raw high resolution time value.
|
static void |
runFinalization()
runFinalization runs the finalize() method of all objects that
are pending for finalization.
|
static void |
runFinalizersOnExit(boolean value)
Deprecated.
running the finalizers is unsafe, therefore this
method is deprecated.
|
static void |
setErr(PrintStream err)
Reassigns the "standard" error output stream.
|
static void |
setIn(InputStream in)
Reassigns the "standard" input stream.
|
static void |
setOut(PrintStream out)
Reassigns the "standard" output stream.
|
static void |
setProperties(Properties props)
Sets the system properties to the
Properties
argument. |
static String |
setProperty(String key,
String value)
setProperty sets property for a given key.
|
static void |
setSecurityManager(SecurityManager s)
Sets the System security.
|
public static final InputStream in
public static final PrintStream out
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data)
See the println
methods in class PrintStream
.
PrintStream.println()
,
PrintStream.println(boolean)
,
PrintStream.println(char)
,
PrintStream.println(char[])
,
PrintStream.println(double)
,
PrintStream.println(float)
,
PrintStream.println(int)
,
PrintStream.println(long)
,
PrintStream.println(java.lang.Object)
,
PrintStream.println(java.lang.String)
public static final PrintStream err
Typically this stream corresponds to display output or another
output destination specified by the host environment or user. By
convention, this output stream is used to display error messages
or other information that should come to the immediate attention
of a user even if the principal output stream, the value of the
variable out
, has been redirected to a file or other
destination that is typically not continuously monitored.
public static int identityHashCode(Object x)
For JamaicaVM, on a 32-bit system, this function returns the object's memory address modified with shift and XOR operations. The hashcode is unique for every object with JamaicaVM.
x
- an object or nullpublic static void setIn(InputStream in)
First, if there is a security manager, its checkPermission
method is called with a RuntimePermission("setIO")
permission
to see if it's ok to reassign the "standard" input stream.
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow
reassigning of the standard input stream.in
- the new standard input stream.SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public static void setOut(PrintStream out)
First, if there is a security manager, its checkPermission
method is called with a RuntimePermission("setIO")
permission
to see if it's ok to reassign the "standard" output stream.
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow
reassigning of the standard output stream.out
- the new standard output streamSecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public static void setErr(PrintStream err)
First, if there is a security manager, its checkPermission
method is called with a RuntimePermission("setIO")
permission
to see if it's ok to reassign the "standard" error output stream.
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow
reassigning of the standard error output stream.err
- the new standard error output stream.SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public static Console console()
Console
object associated
with the current Java virtual machine, if any.public static Channel inheritedChannel() throws IOException
This method returns the channel obtained by invoking the
inheritedChannel
method of the system-wide default
SelectorProvider
object.
In addition to the network-oriented channels described in
inheritedChannel
, this method may return other kinds of
channels in the future.
IOException
- If an I/O error occursSecurityException
- If a security manager is present and it does not
permit access to the channel.public static void setSecurityManager(SecurityManager s)
If there is a security manager already installed, this method first
calls the security manager's checkPermission
method
with a RuntimePermission("setSecurityManager")
permission to ensure it's ok to replace the existing
security manager.
This may result in throwing a SecurityException
.
Otherwise, the argument is established as the current
security manager. If the argument is null
and no
security manager has been established, then no action is taken and
the method simply returns.
SecurityException
- if the security manager has already
been set and its checkPermission
method
doesn't allow it to be replaced.s
- the security manager.getSecurityManager()
,
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public static SecurityManager getSecurityManager()
public static void arraycopy(Object src, int sp, Object dst, int dp, int length)
src and dst must be arrays E[] of a common element type E that is one of boolean, byte, short, char, int, float, long, double or Object.
ensure
(for all i=0..length-1: dst[dp+i] == old src[sp+i]);
NullPointerException
- if src or dst are null. No
modifications are made in this case.ArrayStoreException
- if src or dst is not an array or if
src and dst are arrays of different primitive element types or if
one of src and dst is an array of references and the other array
is an array of primitive types. No modifications are made in these
cases.ArrayStoreException
- if src and dst are reference arrays
and one element of src[sp+k] cannot be stored into dst[dp+k]. In
this case, elements from src[sp+0..sp+k-1] will have been copied
to dst[dp+0..dp+k-1], or, if src==dst and dp>sp, then
src[sp+k+1..sp+length-1] will haven been copied to
dst[dp+k+1..dp+length-1].IndexOutOfBoundsException
- if sp<0 || dp<0 || length<0 ||
sp+length>src.length || dp+length>dst.length.src
- a source arraysp
- start index in srcdst
- (out!) the destination arraydp
- start index in dstlength
- the number of elements to be copied.public static long currentTimeMillis()
The underlying system may have a granularity that is less than this function.
public static Properties getProperties()
First, if there is a security manager, its
checkPropertiesAccess
method is called with no
arguments. This may result in a security exception.
The current set of system properties for use by the
getProperty(String)
method is returned as a
Properties
object. If there is no current set of
system properties, a set of system properties is first created and
initialized. This set of system properties always includes values
for the following keys:
Key | Description of Associated Value |
---|---|
java.version |
Java Runtime Environment version |
java.vendor |
Java Runtime Environment vendor |
java.vendor.url |
Java vendor URL |
java.home |
Java installation directory |
java.vm.specification.version |
Java Virtual Machine specification version |
java.vm.specification.vendor |
Java Virtual Machine specification vendor |
java.vm.specification.name |
Java Virtual Machine specification name |
java.vm.version |
Java Virtual Machine implementation version |
java.vm.vendor |
Java Virtual Machine implementation vendor |
java.vm.name |
Java Virtual Machine implementation name |
java.specification.version |
Java Runtime Environment specification version |
java.specification.vendor |
Java Runtime Environment specification vendor |
java.specification.name |
Java Runtime Environment specification name |
java.class.version |
Java class format version number |
java.class.path |
Java class path |
java.library.path |
List of paths to search when loading libraries |
java.io.tmpdir |
Default temp file path |
java.compiler |
Name of JIT compiler to use |
java.ext.dirs |
Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release. |
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's account name |
user.home |
User's home directory |
user.dir |
User's current working directory |
Multiple paths in a system property value are separated by the path separator character of the platform.
Note that even if the security manager does not permit the
getProperties
operation, it may choose to permit the
getProperty(String)
operation.
SecurityException
- if a security manager exists and its
checkPropertiesAccess
method doesn't allow access
to the system properties.setProperties(java.util.Properties)
,
SecurityException
,
SecurityManager.checkPropertiesAccess()
,
Properties
public static String lineSeparator()
line.separator
.
On UNIX systems, it returns "\n"
; on Microsoft
Windows systems it returns "\r\n"
.
public static void setProperties(Properties props)
Properties
argument.
First, if there is a security manager, its
checkPropertiesAccess
method is called with no
arguments. This may result in a security exception.
The argument becomes the current set of system properties for use
by the getProperty(String)
method. If the argument is
null
, then the current set of system properties is
forgotten.
SecurityException
- if a security manager exists and its
checkPropertiesAccess
method doesn't allow access
to the system properties.props
- the new system properties.getProperties()
,
Properties
,
SecurityException
,
SecurityManager.checkPropertiesAccess()
public static String getProperty(String key)
IllegalArgumentException
- if key is ""NullPointerException
- if key is nullSecurityException
- if a security manager sm is installed
and sm.checkPropertyAccess(key) throws this exception.key
- the property namepublic static String getProperty(String key, String def)
IllegalArgumentException
- if key is ""NullPointerException
- if key is nullSecurityException
- if a security manager sm is installed
and sm.checkPropertyAccess(key) throws this exception.key
- the property namepublic static String setProperty(String key, String value)
IllegalArgumentException
- if key is ""NullPointerException
- if key or value is nullSecurityException
- if a security manager sm is installed
and sm.checkPermission(new PropertyPermission(key,"write"))
throws this exception.key
- the property keyvalue
- the new property valuepublic static String clearProperty(String key)
IllegalArgumentException
- if key is ""NullPointerException
- if key is nullSecurityException
- if a security manager sm is installed
and sm.checkPermission(new PropertyPermission(key,"write"))
throws this exception.key
- the property keypublic static String getenv(String name)
If a security manager exists, its
checkPermission
method is called with a
permission. This may result in a RuntimePermission
("getenv."+name)SecurityException
being thrown. If no exception is thrown the value of the
variable name
is returned.
System
properties and environment variables are both
conceptually mappings between names and values. Both
mechanisms can be used to pass user-defined information to a
Java process. Environment variables have a more global effect,
because they are visible to all descendants of the process
which defines them, not just the immediate Java subprocess.
They can have subtly different semantics, such as case
insensitivity, on different operating systems. For these
reasons, environment variables are more likely to have
unintended side effects. It is best to use system properties
where possible. Environment variables should be used when a
global effect is desired, or when an external system interface
requires an environment variable (such as PATH
).
On UNIX systems the alphabetic case of name
is
typically significant, while on Microsoft Windows systems it is
typically not. For example, the expression
System.getenv("FOO").equals(System.getenv("foo"))
is likely to be true on Microsoft Windows.
NullPointerException
- if name
is null
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow access to the environment variable
name
name
- the name of the environment variablenull
if the variable is not defined in the system environmentgetenv()
,
ProcessBuilder.environment()
public static Map<String,String> getenv()
If the system does not support environment variables, an empty map is returned.
The returned map will never contain null keys or values.
Attempting to query the presence of a null key or value will
throw a NullPointerException
. Attempting to query
the presence of a key or value which is not of type
String
will throw a ClassCastException
.
The returned map and its collection views may not obey the
general contract of the Object.equals(java.lang.Object)
and
Object.hashCode()
methods.
The returned map is typically case-sensitive on all platforms.
If a security manager exists, its
checkPermission
method is called with a
permission. This may result in a RuntimePermission
("getenv.*")SecurityException
being
thrown.
When passing information to a Java subprocess, system properties are generally preferred over environment variables.
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow access to the process environmentgetenv(String)
,
ProcessBuilder.environment()
public static void exit(int status)
This method calls the exit
method in class
Runtime
. This method never returns normally.
The call System.exit(n)
is effectively equivalent to
the call:
Runtime.getRuntime().exit(n)
SecurityException
- if a security manager exists and its checkExit
method doesn't allow exit with the specified status.status
- exit status.Runtime.exit(int)
public static void gc()
For JamaicaVM, a call to Runtime.gc() will perform at least one full garbage collection cycle and at most two full garbage collection cycles. A call to gc() may therefore require a significant amount of time.
Note that running the garbage collector alone does not ensure that memory that is occupied by objects that have a finalize() method will be reclaimed: Their memory will be held until the finalize() method has been executed and the object is found to be unreachable after a second GC cycle. To ensure that all finalizers are executed and the memory of finalized objects is freed, three calls are required as follows:
Runtime.getRuntime().gc(); // find garbage Runtime.getRuntime().runFinalization(); // execute finalizers Runtime.getRuntime().gc(); // recycle finalized objects.
Any weak, soft or phantom references used in JamaicaVM will be updated also via the runFinalization(), i.e., an object to which a weak, soft or phantom reference exist can only be reclaimed when runFinalization() is called either by the finalizer thread or by an application thread,
To increase the overall system performance, it may be wise to run a low-priority thread that calls gc() and runFinalization() perpetually:
while (true) { Runtime.getRuntime().gc(); Runtime.getRuntime().runFinalization(); }
This will use all free CPU time to keep the amount of allocated memory as low as possible, such that memory allocation overhead for all higher-priority threads is minimized.
This function is short hand for Runtime.getRuntime().gc().
public static void runFinalization()
Running the finalizers will permit the garbage collector to reclaim the memory occupied by these objects. However, the memory cannot be reclaimed immediately after execution of finalize(). Instead, since finalize() may have made the object reachable again, the garbage collector first has to show that no new references to the object have been generated. So in the worst case, the garbage collector needs to complete a full GC cycle before the memory can be reclaimed.
In JamaicaVM, runFinalization is wrapped into HeapMemory.executeInArea(), such that it can be called from scoped or immortal memory as well.
This function is short hand for Runtime.getRuntime().runFinalization().
@Deprecated public static void runFinalizersOnExit(boolean value)
For JamaicaVM, the finalizer of boot classes are not run even if this routine was called with a true argument. The reason is that these finalizers would do things like closing System.out, which would make it very hard to do anything useful afterwards.
This function is equivalent to Runtime.runFinalizersOnExit().
SecurityException
- if a security manager is installed and
its checkExit(0) method throws this exception.value
- flagpublic static void load(String filename)
If a security manager sm is installed, sm.checkLink(filename) is called to check the permission to load this library.
Repeated attempts to load the same library will have not effect.
This function is short hand for Runtime.getRuntime().load(String).
NullPointerException
- if filename is nullUnsatisfiedLinkError
- if the library could not be loaded
from the specified file.SecurityException
- if a security manager sm is installed
and sm.checkLink(filename) throws this exception.filename
- absolute pathname of the library to loaded.public static void loadLibrary(String libname)
If a security manager sm is installed, sm.checkLink(filename) is called to check the permission to load this library.
Repeated calls of this method have no effect, any library is loaded only once.
This function is short hand for Runtime.getRuntime().loadLibrary(String).
NullPointerException
- if libname is nullUnsatisfiedLinkError
- if the library with the specified
name could not be loaded.SecurityException
- if a security manager sm is installed
and sm.checkLink(libname) throws this exception.libname
- the library name, excluding path, suffix etc.public static String mapLibraryName(String libname)
NullPointerException
- if libname is null.libname
- the library name, e.g. "m"public static long nanoTime()
On systems with dynamically changing CPU clock speeds, the accuracy may vary dramatically with the changes in CPU clock.
On an overflow of the CPU cycle counter, the result of nanoTime() will drop suddenly from a high positive value to a low negative value. This occurs rarely, e.g., on a 3GHz system with a 64 bit cycle counter, an overflow occurs after 97 years (assuming an initial counter value of 0). When this happens, the difference between the result of nanoTime() and that of a call to nanoTime() before the CPU cycle counter overflow will not be a measure of the time between these two calls.
On a system with a cycle speed of less then 1GHz, an overflow of the nano seconds counter may occur before the CPU cycle counter overflows. In the case of an overflow of the result of nanoTime() will represent the lower 64 bits of the correct nano seconds, i.e. the difference between two consecutive calls will be correct unless the time passed between two calls exceeds about 292 years.
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2022 aicas GmbH. All Rights Reserved.