Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 16: Exploring java.lang 409


System


TheSystemclass holds a collection of static methods and variables. The standard input,
output, and error output of the Java run time are stored in thein,out, anderrvariables.
The methods defined bySystemare shown in Table 16-13. Many of the methods throw
aSecurityExceptionif the operation is not permitted by the security manager.
Let’s look at some common uses ofSystem.

Method Description
static void arraycopy(Objectsource,
intsourceStart,
Objecttarget,
inttargetStart,
intsize)

Copies an array. The array to be copied is passed
insource,and the index at which point the copy will
begin withinsourceis passed insourceStart.The
array that will receive the copy is passed intarget,
and the index at which point the copy will begin
withintargetis passed intargetStart. sizeis the
number of elements that are copied.
static String clearProperty(Stringwhich) Deletes the environmental variable specified by
which.The previous value associated withwhich
is returned.
static Console console ( ) Returns the console associated with the JVM.nullis
returned if the JVM currently has no console. (Added
by Java SE 6.)
static long currentTimeMillis( ) Returns the current time in terms of milliseconds
since midnight, Januar y 1, 1970.
static void exit(intexitCode) Halts execution and returns the value ofexitCodeto
the parent process (usually the operating system).
By convention, 0 indicates normal termination. All
other values indicate some form of error.
static void gc( ) Initiates garbage collection.
static Map<String, String> getenv( ) Returns aMapthat contains the current environmental
variables and their values.
static String getenv(Stringwhich) Returns the value associated with the environmental
variable passed inwhich.
static Properties getProperties( ) Returns the properties associated with the Java
run-time system. (ThePropertiesclass is described
in Chapter 17.)
static String getProperty(Stringwhich) Returns the property associated withwhich.Anull
object is returned if the desired property is not found.
static String getProperty(Stringwhich,
Stringdefault)

Returns the property associated withwhich.If the
desired property is not found,defaultis returned.
static SecurityManager
getSecurityManager( )

Returns the current security manager or anull
object if no security manager is installed.
static int identityHashCode(Objectobj) Returns the identity hash code forobj.

TABLE 16-13 The Methods Defined bySystem
Free download pdf