Java Reference
In-Depth Information
Chapter 23. System Programming
G
LENDOWER
: I can call spirits from the vasty deep. H
OTSPUR
: Why, so
can I, or so can any man; But will they come when you do call for
them?
William Shakespeare,
King Henry IV, Part 1
Sometimes your application must interact with the runtime system of the
Java virtual machine or the underlying operating system. Such interac-
tions include executing other programs, shutting down the runtime sys-
tem, and reading and writing the system properties that allow commu-
nication between the operating system and the runtime system. Three
main classes in
java.lang
provide this access:
•
The
System
class provides static methods to manipulate system
state. It provides for the reading and writing of system properties,
provides the standard input and output streams, and provides a
number of miscellaneous utility functions. For convenience, sever-
al methods in
System
operate on the current
Runtime
object.
•
The
Runtime
class provides an interface to the runtime system of
the executing virtual machine. The current
Runtime
object provides
access to functionality that is per-runtime, such as interacting
with the garbage collector, executing other programs and shutting
down the runtime system.
•
The
Process
class represents a running process that was created by
calling
Runtime.exec
to execute another program, or through direct
use of a
ProcessBuilder
object.
These interactions and others can require security to protect your com-
puter's integrity. So we also look at security and how different security
policies are enforced in the runtime system. We start, though, by looking
at the
System
class.