Chapter 4

Programming in the Large I
methods


ONE WAY TO BREAK UP A COMPLEX PROGRAM into manageable pieces is to use methods. A method 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 method name, it executes all the instructions necessary to carry out the task associated with that method.

methods can be used over and over, at different places in the program. A method can even be used inside another method. This allows you to write simple methods and then use them to help write more complex methods, which can then be used in turn in other methods. 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, methods in Java can be either static or non-static. This chapter covers static methods only. Non-static methods, which are used in true object-oriented programming, will be covered in the next chapter.


Contents of Chapter 4:


[ First Section | Next Chapter | Previous Chapter | Main Index ]