CHAPTER 5
METHODS
CHAPTER GOALS
To be able to implement methods
To become familiar with the concept of parameter passing
To develop strategies for decomposing complex tasks into simpler ones
To be able to determine the scope of a variable
To learn how to think recursively (optional)
CHAPTER CONTENTS
Syntax 5.1: Static Method Declaration
Programming Tip 5.1: Method Comments
Programming Tip 5.2: Do Not Modify Parameter Variables
Common Error 5.1: Trying to Modify Arguments
Common Error 5.2: Missing Return Value
How To 5.1: Implementing a Method
Worked Example 5.1: Generating Random Passwords
5.5 METHODS WITHOUT RETURN VALUES
5.6 PROBLEM SOLVING: REUSABLE METHODS
5.7 PROBLEM SOLVING: STEPWISE REFINEMENT
Programming Tip 5.3: Keep Methods Short
Programming Tip 5.4: Tracing Methods
Worked Example 5.2: Calculating a Course Grade
5.9 RECURSIVE METHODS (OPTIONAL)
Get Java For Everyone: Compatible with Java 5, 6, and 7, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.