Best web design - Chapter 6 Methods 247 Outline 6.1 Introduction 6.2
Chapter 6 Methods 247 Outline 6.1 Introduction 6.2 Program Modules in Java 6.3 Math Class Methods 6.4 Methods 6.5 Method Definitions 6.6 Argument Promotion 6.7 Java API Packages 6.8 Random-Number Generation 6.9 Example: A Game of Chance 6.10 Duration of Identifiers 6.11 6.12 Scope Rules Recursion 6.13 Example Using Recursion: The Fibonacci Series 6.14 Recursion vs. Iteration 6.15 Method Overloading 6.16 Methods of Class JApplet 6.17 (Optional Case Study) Thinking About Objects: Identifying Class Operations Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises 6.1 Introduction Most computer programs that solve real-world problems are much larger than the programs presented in the first few chapters of this text. Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces, or modules. This technique is called divide and conquer. This chapter describes many key features of the Java language that facilitate the design, implementation, operation and maintenance of large programs. 6.2 Program Modules in Java Modules in Java are called methods and classes. Java programs are written by combining new methods and classes the programmer writes with prepackaged methods and classes available in the Java API (also referred to as the Java class library) and in various other method and class libraries. In this chapter, we concentrate on methods; we begin to discuss classes in detail in Chapter 8. The Java API provides a rich collection of classes and methods for performing common mathematical calculations, string manipulations, character manipulations, input/ output operations, error checking and many other useful operations. This set of modules makes the programmer s job easier, because the modules provide many of the capabilities Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01