Java Reference
In-Depth Information
Chapter 3
Introduction to
Parameters and Objects
Introduction
3.1 Parameters
The Mechanics of Parameters
Chapter 2 introduced techniques for managing complexity, including the
use of class constants, which make programs more flexible.This chapter
explores a more powerful technique for obtaining such flexibility. Here,
you will learn how to use parameters to create methods that solve not
just single tasks, but whole families of tasks. Creating such methods
requires you to generalize, or look beyond a specific task to find the more
general category of task that it exemplifies.The ability to generalize is one
of the most important qualities of a good software engineer, and the gen-
eralization technique you will study in this chapter is one of the most
powerful techniques programmers use.After exploring parameters, we'll
discuss some other issues associated with methods, such as the ability of
a method to return a value.
Limitations of Parameters
Multiple Parameters
Parameters versus Constants
Overloading of Methods
3.2 Methods That Return Values
The Math Class
Defining Methods That Return
Values
3.3 Using Objects
String Objects
Interactive Programs and
Scanner Objects
Sample Interactive Program
3.4 Case Study: Projectile
Trajectory
This chapter then introduces the idea of objects and how to use them in
Java programs.We aren't going to explore the details of defining objects
for a while, but we want to begin using objects early. One of the most
attractive features of Java is that it comes with a rich library of predefined
objects that can be used to solve many common programming tasks.
Unstructured Solution
Structured Solution
The chapter concludes with an exploration of a very important kind of
object known as a Scanner . Using a Scanner object, you can write pro-
grams that obtain values from the user. This feature will allow you to
write interactive programs that prompt for input as well as producing
output.
132
 
Search WWH ::




Custom Search