New to Java? We'll help you get started with our revised beginner's tutorial, or our free online textbook.
Get the latest Java books
h t t p : / /w w w . j a v a c o f f e e b r e a k . c o m /
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. 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 3.7, 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.
Contents of Chapter 4:
- Section 1: Black Boxes
- Section 2: Static Subroutines and Static Variables
- Section 3: Parameters
- Section 4: Return Values
- Section 5: Toolboxes, API's, and Packages
- Section 6: More on Program Design
- Section 7: The Truth about Declarations
- Programming Exercises
- Quiz on this Chapter
[ First Section | Next Chapter | Previous Chapter | Main Index ]