CHAPTER 1. THE MENTAL LANDSCAPE 6
multitasking altogether. However, threads have become increasingly important as computers
have become more powerful and as they have begun to make more use of multitasking. Indeed,
threads are built into the Java programming language as a fundamental programming concept.
Just as important in Java and in modern programming in general is the basic concept of
asynchronous events. While programmers don’t actually deal with interrupts directly, they
do often find themselves writing event handlers, which, like interrupt handlers, are called
asynchronous ly when specified events occur. Such “event-driven programming” has a very
different feel fr om the more traditional straight-through, synchron ous programming. We will
begin with the more traditional type of programming, which is still used for programming
individual tasks, but we will return to threads and events later in the text.
∗ ∗ ∗
By the way, the s oftware that does all the interru pt h andling and the communication with
the user and with hardwar e devices is called the operating system. The operating system is
the basic, essential software without which a computer would not be able to function. Other
programs, such as word processors and World Wide Web browsers, are dependent upon the
operating system. Common operating systems include Linux, DOS, Windows 2000, Windows
XP, and the Macintosh OS.
1.3 The Java Virtual Mach ine
Machine language consists of very simple instructions that can be executed directly by
(online)
the CPU of a computer. Almost all programs, thou gh, are written in high-level programming
languages such as Java, Pascal, or C++. A program written in a high-level language cannot
be run directly on any computer. First, it has to be translated into machine language. This
translation can be done by a program called a compiler. A compiler takes a high-level-language
program and trans lates it into an executable machine-language program. O nce the translation
is done, the machine-language program can be run any number of times, but of course it can only
be r un on one type of computer (since each type of computer h as its own individual machine
language). If the program is to run on another type of computer it has to be re-translated,
using a different compiler, into the appropriate mach ine langu age.
There is an alternative to compiling a h igh-level language program. Instead of using a
compiler, which translates the program all at once, you can use an interpreter, wh ich translates
it instruction-by-instruction, as necessary. An interpreter is a program that acts much like a
CPU, with a kind of fetch-and-execute cycle. In order to execute a program, the interpreter
runs in a loop in which it repeatedly reads one instruction from the program, decides what is
necessary to carry out that instruction, and then performs the appropriate machine-language
commands to do so.
One use of interpreters is to execute high-level language programs. For example, the pro-
gramming language Lisp is u s ually executed by an interpreter rather than a compiler. However,
interpreters have another purpose: they can let you use a machine-language program meant for
one type of computer on a completely different type of computer. For example, there is a pro-
gram called “Virtual PC” that runs on Macintosh computers. Virtual PC is an inter preter that
executes mach ine-language programs written for IBM-PC-clone compu ters. If you run Virtual
PC on your Macintosh, you can run any PC program, including programs written for Windows.
(Unfortunately, a PC program will run much more slowly than it would on an actual IBM clone.
The problem is that Virtual PC executes several Macintosh machine-language instructions for