-7%2.5 is -2.0. The IEEE standard defines remainder for x and y differently, preserving symmetry of
spacing along the number linethe result of IEEEremainder(-7,2.5) is 0.5. The IEEE remainder
mechanism keeps resulting values y units apart, as contrasted with the remainder operator's symmetry around
zero. The method is provided because both kinds of remainder are useful.
The static method random generates a pseudorandom number r in the range 0.0 r < 1.0. More control over
pseudorandom number generation is provided by the Random class, as you learned on page 639.
The algorithms used in StrictMath are those defined in the FDLIBM "C" math library; if you need a
complete understanding of these issues, consult The Java™ Language Specification, Third Edition.
See "java.math Mathematics" on page 722 for brief coverage of some other math-related classes.
Exercise 22.15: Write a calculator that has all Math or StrictMath functions, as well as (at least) the basic
operators +, -, *, /, and %. (The simplest form is probably a reverse Polish stack calculator because operator
precedence is not an issue.)
Computers are uselessthey can only give you answers.
Pablo Picasso
Chapter 23. System Programming
GLENDOWER: I can call spirits from the vasty deep. HOTSPUR: 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 interactions include executing other programs, shutting down the runtime
system, and reading and writing the system properties that allow communication 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, several 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 computer'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.