Programming in the Large I
ONE WAY TO BREAK UP A COMPLEX PROGRAM into manageable pieces is to use subroutines. A subroutine consists of the instructions for carrying out a certain task, grouped together and given a name. Elsewhere in the program, that name can be used as a stand-in for the whole set of instructions. That is, as a computer executes a program, whenever it encounters a subroutine name, it executes all the instructions necessary to carry out the task associated with that subroutine.
Subroutines can be used over and over, at different places in the program. A subroutine can even be used inside another subroutine. This allows you to write simple subroutines and then use them to help write more complex subroutines, which can then be used in turn in other subroutines. In this way, very complex programs can be built up step-by-step, where each step in the construction is reasonably simple.
As mentioned in Section 2.6, subroutines in Java can be either static or non-static. This chapter covers static subroutines only. Non-static subroutines, which are used in true object-oriented programming, will be covered in the next chapter.
Sections in Chapter 3:
- Black Boxes
- Static Methods, Static Variables, and Constants
- Return Values
- Toolboxes, API's, and Packages
- More on Program Design
[ First Section | Next Chapter | Previous Chapter | Main Index ]