THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
Returns the current value, in nanoseconds, of the most precise available
system timer. This method can only be used to measure elapsed time and is
not related to any notion of calendar time or wall-clock time, and is not
relative to the epoch. Although the precision is in nanoseconds, there are no
guarantees as to the accuracy.

public static voidarraycopy(Object src, int srcPos, Object
dst, int dstPos, int count)

Copies the contents of the source array, starting at src[srcPos], to the
destination array, starting at dst[dstPos]. Exactly count elements will
be copied. If an attempt is made to access outside either array an
IndexOutOfBoundsException is thrown. If the values in the source
array are not compatible with the destination array an
ArrayStoreException is thrown. "Compatible" means that each object
in the source array must be assignable to the component type of the
destination array. For arrays of primitive types, the types must be the same,
not just assignable; arraycopy cannot be used to copy an array of short
to an array of int. The arraycopy method works correctly on overlapping
arrays, so it can be used to copy one part of an array over another part. You
can, for example, shift everything in an array one slot toward the beginning,
as shown in the method squeezeOut on page 318.

public static intidentityHashCode(Object obj)

Returns a hashcode for obj using the algorithm that Object.hashCode
defines. This allows algorithms that rely on identity hashing to work even if
the class of obj overrides hashCode.

A number of other methods in System are convenience methods that operate on the current Runtime
objectwhich can be obtained via the static method Runtime.getRuntime. For each method an invocation
System.method is equivalent to the invocation Runtime.getRuntime().method; consequently,
these methods are described as we discuss the Runtime class. The methods are


public static void exit(int status)
public static void gc()
public static void runFinalization()
public static void loadLibrary(String libname)
public static void load(String filename)


23.2. Creating Processes


As you have learned, a running system can have many threads of execution. Most systems that host a Java
virtual machine can also run multiple programs. You can execute new programs by using one of the
Runtime.exec convenience methods. Each successful invocation of exec creates a new Process object
that represents the program running in its own process. You can use a Process object to query the process's
state and invoke methods to control its progress. Process is an abstract class whose subclasses are defined
on each system to work with that system's processes. The two basic forms of exec are


public Processexec(String[] cmdArray)tHRows IOException
Free download pdf