Programming and Problem Solving with Java

(やまだぃちぅ) #1

xviii | Preface


morphism. Students learn how to read the documentation for a class hierarchy and how to
determine the inherited members of a class. They also see how the classes are related through
Java’s scope rules. The students are thus brought to the point of being armed with essentially
all of Java’s object-oriented tools with the exception of abstract classes and interfaces.
With Chapter 8,we take a break from our steady uphill climb through the landscape of ob-
ject-oriented programming, and look at a topic that many students find fascinating and fun:
graphical user interfaces. The GUI also provides excellent examples of using objects from a
library. We use just a few Swing components to construct all of the GUI interfaces in the text.
A JFrame provides the basic output window, JLabel is used for output, and JTextField is used
for input. GUI programming requires handling of events, and here we also keep things sim-
ple, using the window’s default exit-on-close handler to terminate execution, and a JButton
to signal when input is ready. These constructs enable us to build typical user interfaces while
we focus on the algorithmic issues of event loops. Chapter 8 develops two case-study appli-
cations that reinforce the object-oriented design approaches in Chapters 6 and 7.
Chapter 9is the “ice cream and cake” section of the book, covering the additional control
structures that make the coding of certain algorithms easier. In addition to the Switch,do, and
forstatements, Chapter 9 introduces the concept of exception handling. We show students
how to use a try-catchstatement to catch exceptions. Because we’ve already covered in-
heritance, it is a simple matter to define new exception classes that can be thrown between
sections of user code. Students are then able to write code that is robust in the face of errors
that cannot be handled directly with testing and branching.
Chapters 10, 11, and 12are devoted to composite data structures. In Chapter 10, the basic
concept of a composite structure is introduced and illustrated with the Java array. In Chapter
11, we show how an array can be used to implement a general-purpose list class. Our prior
class designs have been in the context of specific applications, and this provides experience
in developing an object-oriented design that does not have a predefined client. Then in
Chapter 12, we extend the discussion of arrays to multiple dimensions, and through a case
study we show how they can be used to represent mathematical matrices. Given this nu-
merically motivated case study, it is also natural to review the limitations of floating-point
numbers as they are represented in the computer.
Chapter 13provides a quick tour of the concept of recursion and some example algo-
rithms. As in our previous texts, this chapter is designed so that it can be assigned for read-
ing along with earlier chapters. The first half of the chapter can be covered after Chapter 5,
The second half of the chapter can be read after Chapter 10, as it applies recursion to arrays.
The book closes with Chapter 14, devoted to the implementation of Java applets. We specif-
ically chose to use only applications in the first part of the text because of their more gen-
eral applicability, their ability to use console I/O, and to avoid various issues with portability
across browsers in different environments. We recognize, however, that many students are
interested in web programming, and are curious to learn how to write applets. Chapter 14
thus serves this interest.
Free download pdf