Objects First with Java-0130449296.pdf
(
5671 KB
)
Pobierz
252484745 UNPDF
David Barnes
Michael Kölling
Objects First with Java
A Practical Introduction using BlueJ
FOR EVALUATION ONLY
NOT FOR DISTRIBUTION
Copyright © Barnes, Kölling, 2002
Pearson Education / Prentice Hall
ISBN 0-13-044929-6
1
Contents
LIST OF PROJECTS DISCUSSED IN DETAIL IN THIS BOOK
11
PREFACE TO THE INSTRUCTOR
14
PART I: Foundations of object orientation
CHAPTER 1 OBJECTS AND CLASSES
23
1.1 Objects and classes
23
1.3 Calling methods
25
1.4 Parameters
26
1.5 Data types
27
1.6 Multiple instances
28
1.7 State
28
1.8 What is in an object?
29
1.9 Object interaction
31
1.10 Source code
32
1.11 Another example
33
1.12 Return values
33
1.13 Objects as parameters
34
1.14 Summary
36
Terms introduced in this chapter
36
Concept summary
36
CHAPTER 2 UNDERSTANDING CLASS DEFINITIONS
38
2.1 Ticket machines
38
2.1.1 Exploring the behavior of a naïve ticket machine
39
2.2 Examining a class definition
39
2.3 Fields, constructors, and methods
42
2.3.3 Constructors
44
2.4 Passing data via parameters
46
2.6 Accessor methods
48
2.7 Mutator methods
50
2.8 Printing from methods
52
2.9 Summary of the naïve ticket machine
54
2
1.2 Creating objects
24
2.3.2 Fields
43
2.5 Assignment
47
2.10 Reflecting on the design of the ticket machine
55
2.11 Making choices: the conditional statement
56
2.12 A further conditional-statement example
59
2.14 Fields, parameters, and local variables
61
2.15 Summary of the better ticket machine
62
2.16 Reviewing a familiar example
62
2.17 Summary
65
Terms introduced in this chapter
66
Concept summary
66
CHAPTER 3 OBJECT INTERACTION
70
3.1 The clock example
70
3.2 Abstraction and modularization
71
3.4 Modularization in the clock example
72
3.5 Implementing the clock display
73
3.6 Class diagrams versus object diagrams
74
3.7 Primitive types and object types
75
3.8 The ClockDisplay source code
76
3.8.1 Class NumberDisplay
77
3.8.2 String concatenation
78
3.8.3 The modulo operator
80
3.8.4 Class ClockDisplay
80
3.9 Objects creating objects
83
3.10 Multiple constructors
84
3.11.1 Internal method calls
85
3.11.2 External method calls
85
3.11.3 Summary of the clock display
87
3.12 Another example of object interaction
87
3.12.1 The mail system example
88
3.12.2 The this keyword
89
3.13 Using a debugger
91
3.13.2 Setting breakpoints
91
3.13.3 Single stepping
93
3.13.4 Stepping into methods
94
3.14 Method calling revisited
95
Terms introduced in this chapter
96
Concept summary
97
CHAPTER 4 GROUPING OBJECTS
98
4.1 Grouping objects in flexible-size collections
98
4.2 A personal notebook
99
4.3 A first look at library classes
99
4.4 Object structures with collections
101
3
2.13 Local variables
60
3.3 Abstraction in software
72
3.11 Method calls
85
3.15 Summary
96
4.3.1 An example of using a library
99
4.5 Numbering within collections
103
4.6 Removing an item from a collection
103
4.7 Processing a whole collection
104
4.7.2 Iterating over a collection
107
4.7.3 Index access versus iterators
108
4.8 Summary of the notebook example
108
4.9 Another example – an auction system
109
4.9.1 The Lot class
109
4.9.2 The Auction class
110
4.9.3 Casting
112
4.10 Fixed-size collections
113
4.10.1 A log-file analyzer
114
4.10.2 Declaring array variables
116
4.10.3 Creating array objects
117
4.10.4 Using array objects
118
4.10.5 Analyzing the log file
119
4.10.6 The for loop
119
4.11 Summary
123
Terms introduced in this chapter
123
Concept summary
123
CHAPTER 5 MORE SOPHISTICATED BEHAVIOR
125
5.1 Documentation for library classes
126
5.2.1 Exploring the TechSupport System
127
5.2.2 Reading the code
131
5.3 Reading class documentation
132
5.3.2 Interfaces versus implementation
133
5.3.3 Using library-class methods
134
5.3.4 Checking string equality
136
5.4 Adding Random behavior
136
5.4.1 The Random class
137
5.4.2 Random numbers with limited range
138
5.4.3 Generating random responses
139
5.5 Packages and import
141
5.6 Using maps for associations
142
5.6.2 The concept of a map
143
5.6.3 Using a HashMap
143
5.6.4 Using a map for the TechSupport system
144
5.7 Using sets
146
5.9 Finishing the TechSupport system
147
5.10 Writing class documentation
150
5.10.1 Using javadoc in BlueJ
151
5.10.2 Elements of class documentation
151
5.11 Public versus private
153
5.11.1 Information hiding
154
5.11.2 Private methods and public fields
154
5.12 Learning about classes from their interfaces
155
5.13 Class variables and constants
158
4
4.7.1 The while loop
105
5.2 The TechSupport System
127
5.8 Tokenizing Strings
148
5.13.2 The static keyword
158
5.13.3 Constants
160
5.14 Summary
160
Terms introduced in this chapter
160
Concept summary
161
CHAPTER 6 WELL-BEHAVED OBJECTS
163
6.1 Introduction
163
6.2 Testing and debugging
164
6.3 Unit testing within BlueJ
164
6.3.1 Using inspectors
168
6.3.2 Positive versus negative testing
170
6.4 Test automation
170
6.4.1 Regression testing
170
6.4.2 Automated checking of test results
173
6.5 Modularization and interfaces
174
6.6 A debugging scenario
176
6.7 Commenting and style
176
6.8 Manual walkthroughs
177
6.8.1 A high-level walkthrough
178
6.8.2 Checking state with a walkthrough
180
6.8.3 Verbal walkthroughs
182
6.9 Print statements
183
6.9.2 Turning debugging information on or off
185
6.10 Debuggers
186
6.11 Putting the techniques into practice
187
Concept summary
187
CHAPTER 7 DESIGNING CLASSES
188
7.1 Introduction
188
7.3 Introduction to coupling and cohesion
190
7.4 Code duplication
193
7.5 Making extensions
196
7.5.1 The task
196
7.5.2 Finding the relevant source code
196
7.6 Coupling
198
7.6.1 Using encapsulation to reduce coupling
198
7.7 Responsibility-driven design
202
7.7.1 Responsibilities and coupling
202
7.8 Localizing change
205
7.9 Implicit coupling
205
7.10 Thinking ahead
208
7.11.1 Cohesion of methods
209
7.11.2 Cohesion of classes
210
7.11.3 Cohesion for readability
211
5
Terms introduced in this chapter
187
7.2 The world-of-zuul game example
192
7.11 Cohesion
209
Plik z chomika:
maszter
Inne pliki z tego folderu:
vanRoyHaridi2003-book.pdf
(3512 KB)
Introduction to Computer Graphics.pdf
(3489 KB)
^Algorytmy, struktury danych i techniki programowania.pdf
(43866 KB)
Wstep do informatyki.pdf
(673 KB)
php.pdf
(6235 KB)
Inne foldery tego chomika:
angielski
Dokumenty
filmy
ksiazki_fizyka
ksiazki_logika
Zgłoś jeśli
naruszono regulamin