|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.System
public final class System
System contains static fields and methods that permit access to properties of the current environment. This includes standard input, output and error streams, environment variables and security manager.
Field Summary | |
---|---|
static PrintStream |
err
The standard error stream. |
static InputStream |
in
The standard input stream. |
static PrintStream |
out
The standard output stream. |
Method Summary | |
---|---|
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()
|
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)
exit terminates the currently running Java application and the VM. |
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()
getProperties returns the 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()
inheritedChannel |
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)
setErr sets System.err to a new value. |
static void |
setIn(InputStream in)
setIn sets System.in to a new value. |
static void |
setOut(PrintStream out)
setOut sets System.out to a new value. |
static void |
setProperties(Properties props)
Set the current set of system properties to the given argument. |
static String |
setProperty(String key,
String value)
setProperty sets property for a given key. |
static void |
setSecurityManager(SecurityManager s)
setSecurityManager sets a new security manager. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final InputStream in
NOTE: This field is not as final as it may seem, its value can be modified by a call to setIn.
public static final PrintStream out
NOTE: This field is not as final as it may seem, its value can be modified by a call to setOut.
public static final PrintStream err
NOTE: This field is not as final as it may seem, its value can be modified by a call to setErr.
Method Detail |
---|
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 null
public static void setIn(InputStream in)
in
- new value for System.in
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new RuntimePermission("setIO")) throws
this exception.public static void setOut(PrintStream out)
out
- new value for System.out
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new RuntimePermission("setIO")) throws
this exception.public static void setErr(PrintStream err)
err
- new value for System.err
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new RuntimePermission("setIO")) throws
this exception.public static void setSecurityManager(SecurityManager s)
ensure
(getSecurityManager() == s)
s
- the new security manager, null to reset the security
manager
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new RuntimePermission("setSecurityManager"))
throws this exception.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]);
src
- a source arraysp
- start index in srcdst
- (out!) the destination arraydp
- start index in dstlength
- the number of elements to be copied.
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.public static long currentTimeMillis()
The underlying system may have a granularity that is less than this function.
public static Properties getProperties()
setProperties(Properties)
).
The standard properties include:
java.version Java version java.vendor Java vendor (aicas GmbH in this case) java.vendor.url Java vendor URL (http://www.aicas.com) java.home VM's home directory java.vm.specification.version JVM spec version java.vm.specification.vendor JVM spec vendor java.vm.specification.name JVM spec name java.vm.version JVM version java.vm.vendor JVM vendor (aicas GmbH) java.vm.name JVM name (JamaicaVM) java.specification.version Java spec version java.specification.vendor Java spec vendor java.specification.name Java spec name java.class.version Java class file version java.class.path Java classpath java.library.path Java shared library path java.io.tmpdir path for temporary directory java.compiler Compiler used java.ext.dirs extension library directory os.name OS name os.arch CPU architecture os.version OS version file.separator "/" on Linux, "\\" on Windows, etc. path.separator ":" on Linux, ";" on Windows, etc. line.separator "\n" on Linux, "\n\r" on Windows, etc. user.name user login name user.home user home directory user.dir current working directory
SecurityException
- if a security manager sm is installed
and sm.checkPropertiesAccess() throws this exception.public static void setProperties(Properties props)
props
- the new properties. null to erase all current
properties.
SecurityException
- if a security manager is installed and
its checkPropertiesAccess() method throws this exception.public static String getProperty(String key)
key
- the property name
IllegalArgumentException
- if key is ""
NullPointerException
- if key is null
SecurityException
- if a security manager sm is installed
and sm.checkPropertyAccess(key) throws this exception.public static String getProperty(String key, String def)
key
- the property name
IllegalArgumentException
- if key is ""
NullPointerException
- if key is null
SecurityException
- if a security manager sm is installed
and sm.checkPropertyAccess(key) throws this exception.public static String setProperty(String key, String value)
key
- the property keyvalue
- the new property value
IllegalArgumentException
- if key is ""
NullPointerException
- if key or value is null
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new PropertyPermission(key,"write"))
throws this exception.public static String clearProperty(String key)
key
- the property key
IllegalArgumentException
- if key is ""
NullPointerException
- if key is null
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new PropertyPermission(key,"write"))
throws this exception.public static String getenv(String name)
name
- name of the environment variable
NullPointerException
- if name is null *
SecurityException
- if a security manager sm is installed
and sm.checkPermission(new RuntimePermission("getenv." + name))
throws this exception.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 function is short hand for Runtime.getRuntime().exit(status).
status
- exit status, 0 for ok.
SecurityException
- if a security manager is installed and
its checkExit(status) method throws this exception.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().
value
- flag
SecurityException
- if a security manager is installed and
its checkExit(0) method throws this exception.public 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).
filename
- absolute pathname of the library to loaded.
NullPointerException
- if filename is null
UnsatisfiedLinkError
- 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.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).
libname
- the library name, excluding path, suffix etc.
NullPointerException
- if libname is null
UnsatisfiedLinkError
- 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.public static String mapLibraryName(String libname)
libname
- the library name, e.g. "m"
NullPointerException
- if libname is null.public static Channel inheritedChannel() throws IOException
IOException
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.
public static Console console()
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |