When you write a program, you perform two basic tasks: you define your data structures, then define the operations to perform on the data. In the Java virtual machine, the fundamental unit of operation is the instruction, which causes the JVM to perform a simple operation such as adding two numbers or retrieving a value from the heap. Each instruction by itself performs only a tiny piece of an overall task.
Instructions are collected into a unit called a method. The instructions in a method work together to perform a task such as multiplying matrices or drawing a three-dimensional figure on the screen. Methods may have just a few instructions or several thousand. A method has the ability to repeat parts of its code and skip over other parts. Many methods use other methods to assist in their task.
As we saw in chapter 2, methods are grouped together into classes, which define the data structures and the methods performed on them. A program is a collection of tasks taken together. Each program performs a complex task for the user, such as word processing or scanning through astronomical data looking for new quasars.
This chapter and the next few discuss the process of writing methods. This is partly a matter of learning which operations are provided by the JVM. You will also learn how these instructions fit together to perform useful computational tasks.
We start with basic instructions to manipulate the JVM's data storage areas and to perform arithmetic. We proceed by learning to use JVM objects. Finally, we discuss how JVM methods can control their own flow of execution to perform some tasks repeatedly and others not at all.