Programming and Problem Solving with Java

(やまだぃちぅ) #1

9


CHAPTER


this book we have said that a construct could
cause an exception. Until now, we have handled exceptions by forwarding
them to “someone else.” In this chapter, we stop passing the buck and ex-
amine how to handle exceptions within our code. We also show you how
to generate exceptions of your own.
In Chapters 4 and 5, we introduced the Java statements for the se-
lection and loop control structures. In some cases, we considered more
than one way of implementing these structures. For example, selection
may be implemented by an ifstructure. Although the if-(then)is suffi-
cient to implement any selection structure, Java also provides the if-else
for the sake of convenience—the two-way branch is used frequently in
programming.
This chapter introduces several new statements that are also
nonessential to, but nonetheless convenient for, programming. The switch
statement makes it easier to write selection structures that have many
branches. Two new looping statements,forand do, make it easier to pro-
gram certain types of loops. The breakand continuestatements are con-
trol statements that are used as part of larger looping and selection
structures.
Finally, we examine the remaining operators in Java and study their
place in the precedence hierarchy.


Several times throughout

1972
Steve Wozniak
makes free phone
calls using his
invention, the “blue
box”

1973
Xerox PARC’s
experimental Alto
personal computer,
featuring a mouse,
a graphical user
interface, and
connection to a local
area network,
becomes operational

1973
Ten thousand
components are
placed on a 1-
square-cm chip
through large-scale
integration

1973
Eckert and
Mauchley’s ENIAC
patent is invali-
dated, and John
Vincent Atanasoff is
federally recognized
as the inventor of
the modern
computer

1974
Charles Simonyi
writes the first
WYSIWYG (“What
You See Is What
You Get”) program
entitled Bravo

1974
The first World
Computer Chess
Tournament takes
place in Stockholm;
the winner is the
program Kaissa
Free download pdf