Chapter 1 Getting Started |
|
1 | (56) |
|
|
2 | (11) |
|
Origins of the Java Language |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
4 | (1) |
|
A Sample Java Application Program |
|
|
5 | (3) |
|
Byte-Code and the Java Virtual Machine |
|
|
8 | (2) |
|
|
10 | (1) |
|
Compiling a Java Program or Class |
|
|
10 | (1) |
|
|
11 | (2) |
|
|
12 | (1) |
|
1.2 Expressions And Assignment Statements |
|
|
13 | (20) |
|
|
13 | (2) |
|
|
15 | (1) |
|
|
16 | (3) |
|
Tip: Initialize Variables |
|
|
18 | (1) |
|
More Assignment Statements |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (2) |
|
Arithmetic Operators and Expressions |
|
|
23 | (1) |
|
Parentheses and Precedence Rules |
|
|
24 | (2) |
|
Integer and Floating-Point Division |
|
|
26 | (3) |
|
PitFall: Round-Off Errors in Floating-Point Numbers |
|
|
27 | (1) |
|
PitFall: Division with Whole Numbers |
|
|
28 | (1) |
|
|
29 | (1) |
|
Increment and Decrement Operators |
|
|
30 | (3) |
|
|
33 | (13) |
|
String Constants and Variables |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
35 | (2) |
|
|
37 | (5) |
|
|
42 | (1) |
|
|
43 | (1) |
|
The Unicode Character Set |
|
|
43 | (3) |
|
|
46 | (11) |
|
|
46 | (2) |
|
Java Spelling Conventions |
|
|
48 | (1) |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
51 | (1) |
|
Answers to Self-Test Exercises |
|
|
52 | (2) |
|
|
54 | (3) |
Chapter 2 Console Input and Output |
|
57 | (42) |
|
|
58 | (18) |
|
|
58 | (3) |
|
Tip: Different Approaches to Formatting Output |
|
|
61 | (1) |
|
Formatting Output with printf |
|
|
61 | (6) |
|
Tip: Formatting Monetary Amounts with printf |
|
|
65 | (1) |
|
|
66 | (1) |
|
Money Formats Using NumberFormat |
|
|
67 | (3) |
|
Importing Packages and Classes |
|
|
70 | (2) |
|
|
72 | (4) |
|
2.2 Console Input Using The Scanner Class |
|
|
76 | (13) |
|
|
76 | (8) |
|
PitFall: Dealing with the Line Terminator, '\n' |
|
|
83 | (1) |
|
|
84 | (3) |
|
|
84 | (1) |
|
|
84 | (2) |
|
Example: Self-Service Checkout |
|
|
86 | (1) |
|
|
87 | (2) |
|
2.3 Introduction To File Input |
|
|
89 | (10) |
|
The Scanner Class for Text File Input |
|
|
89 | (3) |
|
|
92 | (1) |
|
Answers to Self-Test Exercises |
|
|
92 | (3) |
|
|
95 | (4) |
Chapter 3 Flow of Control |
|
99 | (74) |
|
|
100 | (13) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (2) |
|
|
103 | (1) |
|
|
104 | (1) |
|
Multiway if-else Statement |
|
|
104 | (3) |
|
Example: State Income Tax |
|
|
105 | (2) |
|
|
107 | (5) |
|
PitFall: Forgetting a break in a switch Statement |
|
|
111 | (1) |
|
|
112 | (1) |
|
|
113 | (19) |
|
Simple Boolean Expressions |
|
|
113 | (3) |
|
PitFall: Using = in Place of == |
|
|
114 | (1) |
|
PitFall: Using == with Strings |
|
|
115 | (1) |
|
Lexicographic and Alphabetic Order |
|
|
116 | (3) |
|
Building Boolean Expressions |
|
|
119 | (1) |
|
PitFall: Strings of Inequalities |
|
|
120 | (1) |
|
Evaluating Boolean Expressions |
|
|
120 | (4) |
|
Tip: Naming Boolean Variables |
|
|
123 | (1) |
|
Short-Circuit and Complete Evaluation |
|
|
124 | (1) |
|
Precedence and Associativity Rules |
|
|
125 | (7) |
|
|
132 | (18) |
|
while Statement and do-while Statement |
|
|
132 | (2) |
|
Algorithms and Pseudocode |
|
|
134 | (4) |
|
Example: Averaging a List of Scores |
|
|
137 | (1) |
|
|
138 | (3) |
|
The Comma in for Statements |
|
|
141 | (4) |
|
Tip: Repeat N Times Loops |
|
|
143 | (1) |
|
PitFall: Extra Semicolon in a for Statement |
|
|
143 | (1) |
|
|
144 | (1) |
|
|
145 | (3) |
|
The break and continue Statements |
|
|
148 | (1) |
|
|
149 | (1) |
|
|
150 | (9) |
|
|
150 | (1) |
|
|
150 | (1) |
|
General Debugging Techniques |
|
|
151 | (5) |
|
Example: Debugging an Input Validation Loop |
|
|
152 | (4) |
|
|
156 | (1) |
|
|
157 | (2) |
|
3.5 Random Number Generation |
|
|
159 | (14) |
|
|
160 | (1) |
|
|
161 | (1) |
|
|
162 | (1) |
|
Answers to Self-Test Exercises |
|
|
162 | (6) |
|
|
168 | (5) |
Chapter 4 Defining Classes I |
|
173 | (86) |
|
|
174 | (33) |
|
Instance Variables and Methods |
|
|
177 | (3) |
|
|
180 | (6) |
|
Tip: Any Method Can Be Used as a void Method |
|
|
184 | (2) |
|
|
186 | (1) |
|
|
187 | (1) |
|
Tip: Declaring Variables in a for Statement |
|
|
188 | (1) |
|
Parameters of a Primitive Type |
|
|
188 | (9) |
|
PitFall: Use of the Terms "Parameter" and "Argument" |
|
|
195 | (2) |
|
Simple Cases with Class Parameters |
|
|
197 | (1) |
|
|
197 | (2) |
|
Methods That Return a Boolean Value |
|
|
199 | (3) |
|
The Methods equals and tostring |
|
|
202 | (3) |
|
|
205 | (2) |
|
|
205 | (2) |
|
4.2 Information Hiding And Encapsulation |
|
|
207 | (11) |
|
public and private Modifiers |
|
|
208 | (2) |
|
Example: Yet Another Date Class |
|
|
209 | (1) |
|
Accessor and Mutator Methods |
|
|
210 | (7) |
|
Tip: A Class Has Access to Private Members of All Objects of the Class |
|
|
215 | (1) |
|
Tip: Mutator Methods Can Return a Boolean Value |
|
|
216 | (1) |
|
Preconditions and Postconditions |
|
|
217 | (1) |
|
|
218 | (8) |
|
|
218 | (8) |
|
PitFall: Overloading and Automatic Type Conversion |
|
|
222 | (2) |
|
PitFall: You Cannot Overload Based on the Type Returned |
|
|
224 | (2) |
|
|
226 | (33) |
|
|
226 | (11) |
|
Tip: You Can Invoke Another Method in a Constructor |
|
|
234 | (1) |
|
Tip: A Constructor Has a this Parameter |
|
|
234 | (1) |
|
Tip: Include a No-Argument Constructor |
|
|
235 | (1) |
|
Example: The Final Date Class |
|
|
236 | (1) |
|
Default Variable Initializations |
|
|
237 | (1) |
|
An Alternative Way to Initialize Instance Variables |
|
|
237 | (5) |
|
Example: A Pet Record Class |
|
|
238 | (4) |
|
The StringTokenizer Class |
|
|
242 | (5) |
|
|
247 | (1) |
|
Answers to Self-Test Exercises |
|
|
248 | (5) |
|
|
253 | (6) |
Chapter 5 Defining Classes II |
|
259 | (86) |
|
5.1 Static Methods And Static Variables |
|
|
261 | (23) |
|
|
261 | (7) |
|
PitFall: Invoking a Nonstatic Method Within a Static Method |
|
|
263 | (1) |
|
Tip: You Can Put a main in Any Class |
|
|
264 | (4) |
|
|
268 | (5) |
|
|
273 | (4) |
|
|
277 | (1) |
|
Automatic Boxing and Unboxing |
|
|
278 | (2) |
|
Static Methods in Wrapper Classes |
|
|
280 | (4) |
|
PitFall: A Wrapper Class Does Not Have a No-Argument Constructor |
|
|
283 | (1) |
|
5.2 References And Class Parameters |
|
|
284 | (19) |
|
|
285 | (1) |
|
|
286 | (5) |
|
|
291 | (6) |
|
PitFall: Use of = and == with Variables of a Class Type |
|
|
295 | (2) |
|
|
297 | (1) |
|
PitFall: Null Pointer Exception |
|
|
298 | (1) |
|
The new Operator and Anonymous Objects |
|
|
298 | (5) |
|
Example: Another Approach to Keyboard Input |
|
|
299 | (2) |
|
|
301 | (2) |
|
5.3 Using And Misusing References |
|
|
303 | (19) |
|
|
304 | (5) |
|
PitFall: null Can Be an Argument to a Method |
|
|
309 | (4) |
|
|
313 | (6) |
|
|
315 | (4) |
|
Mutable and Immutable Classes |
|
|
319 | (3) |
|
Tip: Deep Copy versus Shallow Copy |
|
|
321 | (1) |
|
Tip: Assume Your Coworkers Are Malicious |
|
|
322 | (1) |
|
|
322 | (23) |
|
Packages and import Statements |
|
|
323 | (1) |
|
|
324 | (1) |
|
Package Names and Directories |
|
|
324 | (3) |
|
PitFall: Subdirectories Are Not Automatically Imported |
|
|
327 | (1) |
|
|
327 | (1) |
|
PitFall: Not Including the Current Directory in Your Class Path |
|
|
328 | (1) |
|
Specifying a Class Path When You Compile |
|
|
328 | (1) |
|
|
329 | (1) |
|
|
330 | (1) |
|
Commenting Classes for javadoc |
|
|
330 | (2) |
|
|
332 | (2) |
|
|
334 | (1) |
|
Answers to Self-Test Exercises |
|
|
335 | (4) |
|
|
339 | (6) |
Chapter 6 Arrays |
|
345 | (82) |
|
6.1 Introduction To Arrays |
|
|
346 | (10) |
|
Creating and Accessing Arrays |
|
|
347 | (3) |
|
The length Instance Variable |
|
|
350 | (3) |
|
Tip: Use for Loops with Arrays |
|
|
352 | (1) |
|
PitFall: Array Indices Always Start with Zero |
|
|
352 | (1) |
|
PitFall: Array Index Out of Bounds |
|
|
352 | (1) |
|
|
353 | (3) |
|
PitFall: An Array of Characters Is Not a String |
|
|
355 | (1) |
|
6.2 Arrays And References |
|
|
356 | (12) |
|
|
356 | (2) |
|
PitFall: Arrays with a Class Base Type |
|
|
358 | (1) |
|
|
358 | (7) |
|
PitFall: Use of = and == with Arrays |
|
|
360 | (5) |
|
Arguments for the Method main |
|
|
365 | (2) |
|
Methods that Return an Array |
|
|
367 | (1) |
|
6.3 Programming With Arrays |
|
|
368 | (31) |
|
|
369 | (7) |
|
Example: A Class for Partially Filled Arrays |
|
|
372 | (4) |
|
Tip: Accessor Methods Need Not Simply Return Instance Variables |
|
|
376 | (1) |
|
|
376 | (4) |
|
Methods with a Variable Number of Parameters |
|
|
380 | (4) |
|
Example: A String Processing Example |
|
|
383 | (1) |
|
Privacy Leaks with Array Instance Variables |
|
|
384 | (8) |
|
Example: Sorting an Array |
|
|
388 | (4) |
|
|
392 | (7) |
|
Tip: Enumerated Types in switch Statements |
|
|
397 | (2) |
|
6.4 Multidimensional Arrays |
|
|
399 | (28) |
|
Multidimensional Array Basics |
|
|
399 | (3) |
|
Using the length Instance Variable |
|
|
402 | (1) |
|
|
403 | (1) |
|
Multidimensional Array Parameters and Returned Values |
|
|
403 | (7) |
|
Example: A Grade Book Class |
|
|
404 | (6) |
|
|
410 | (1) |
|
Answers to Self-Test Exercises |
|
|
411 | (7) |
|
|
418 | (9) |
Chapter 7 Inheritance |
|
427 | (56) |
|
|
428 | (24) |
|
|
429 | (10) |
|
Overriding a Method Definition |
|
|
439 | (1) |
|
Changing the Return Type of an Overridden Method |
|
|
439 | (1) |
|
Changing the Access Permission of an Overridden Method |
|
|
440 | (2) |
|
PitFall: Overriding versus Overloading |
|
|
441 | (1) |
|
|
442 | (2) |
|
|
444 | (8) |
|
Tip: An Object of a Derived Class Has More than One Type |
|
|
445 | (3) |
|
PitFall: The Terms Subclass and Superclass |
|
|
448 | (1) |
|
Example: An Enhanced StringTokenizer Class |
|
|
449 | (3) |
|
7.2 Encapsulation And Inheritance |
|
|
452 | (9) |
|
PitFall: Use of Private Instance Variables from the Base Class |
|
|
453 | (1) |
|
PitFall: Private Methods Are Effectively Not Inherited |
|
|
454 | (1) |
|
Protected and Package Access |
|
|
455 | (6) |
|
PitFall: Forgetting about the Default Package |
|
|
458 | (1) |
|
PitFall: A Restriction on Protected Access |
|
|
458 | (3) |
|
7.3 Programming With Inheritance |
|
|
461 | (22) |
|
Tip: Static Variables Are Inherited |
|
|
461 | (1) |
|
Tip: "is a" versus "has a" |
|
|
461 | (1) |
|
Access to a Redefined Base Method |
|
|
461 | (3) |
|
PitFall: You Cannot Use Multiple supers |
|
|
463 | (1) |
|
|
464 | (1) |
|
The Right Way to Define equals |
|
|
465 | (7) |
|
Tip: getClass versus instanceof |
|
|
467 | (5) |
|
|
472 | (1) |
|
Answers to Self-Test Exercises |
|
|
473 | (3) |
|
|
476 | (7) |
Chapter 8 Polymorphism and Abstract Classes |
|
483 | (40) |
|
|
484 | (25) |
|
|
485 | (2) |
|
|
487 | (8) |
|
|
488 | (7) |
|
Late Binding with toString |
|
|
495 | (2) |
|
PitFall: No Late Binding for Static Methods |
|
|
496 | (1) |
|
Downcasting and Upcasting |
|
|
497 | (7) |
|
|
501 | (1) |
|
Tip: Checking to See Whether Downcasting Is Legitimate |
|
|
501 | (3) |
|
A First Look at the clone Method |
|
|
504 | (5) |
|
PitFall: Sometimes the clone Method Return Type Is Object |
|
|
505 | (1) |
|
PitFall: Limitations of Copy Constructors |
|
|
506 | (3) |
|
|
509 | (14) |
|
|
510 | (6) |
|
PitFall: You Cannot Create Instances of an Abstract Class |
|
|
514 | (1) |
|
Tip: An Abstract Class Is a Type |
|
|
515 | (1) |
|
|
516 | (1) |
|
Answers to Self-Test Exercises |
|
|
516 | (2) |
|
|
518 | (5) |
Chapter 9 Exception Handling |
|
523 | (58) |
|
9.1 Exception Handling Basics |
|
|
525 | (31) |
|
|
525 | (2) |
|
Exception Handling with the Scanner Class |
|
|
527 | (3) |
|
Tip: Exception Controlled Loops |
|
|
528 | (2) |
|
|
530 | (7) |
|
Example: A Toy Example of Exception Handling |
|
|
532 | (5) |
|
|
537 | (1) |
|
Exception Classes from Standard Packages |
|
|
538 | (2) |
|
Defining Exception Classes |
|
|
540 | (11) |
|
|
544 | (2) |
|
Tip: An Exception Class Can Carry a Message of Any Type |
|
|
546 | (5) |
|
|
551 | (5) |
|
PitFall: Catch the More Specific Exception First |
|
|
553 | (3) |
|
9.2 Throwing Exceptions In Methods |
|
|
556 | (13) |
|
Throwing an Exception in a Method |
|
|
556 | (2) |
|
Declaring Exceptions in a throws Clause |
|
|
558 | (3) |
|
Exceptions to the Catch or Declare Rule |
|
|
561 | (1) |
|
throws Clause in Derived Classes |
|
|
562 | (1) |
|
|
563 | (1) |
|
Example: Retrieving a High Score |
|
|
564 | (3) |
|
|
567 | (2) |
|
9.3 More Programming Techniques For Exception Handling |
|
|
569 | (12) |
|
PitFall: Nested try-catch Blocks |
|
|
569 | (1) |
|
|
569 | (2) |
|
|
571 | (1) |
|
|
571 | |
|
ArrayIndexOutOfBoundsException |
|
|
569 | (3) |
|
|
572 | (1) |
|
Answers to Self-Test Exercises |
|
|
573 | (4) |
|
|
577 | (4) |
Chapter 10 File I/O |
|
581 | (70) |
|
10.1 Introduction TO FILE I/O |
|
|
582 | (2) |
|
|
582 | (1) |
|
Text Files and Binary Files |
|
|
583 | (1) |
|
|
584 | (29) |
|
|
584 | (7) |
|
PitFall: A try Block Is a Block |
|
|
590 | (1) |
|
PitFall: Overwriting an Output File |
|
|
590 | (1) |
|
|
591 | (2) |
|
Tip: toString Helps with Text File Output |
|
|
592 | (1) |
|
|
593 | (1) |
|
Reading a Text File Using Scanner |
|
|
593 | (3) |
|
Testing for the End of a Text File with scanner |
|
|
596 | (7) |
|
Reading a Text File Using BufferedReader |
|
|
603 | (4) |
|
Tip: Reading Numbers with BufferedReader |
|
|
607 | (1) |
|
Testing for the End of a Text File with BufferedReader |
|
|
607 | (2) |
|
|
609 | (1) |
|
Nested Constructor Invocations |
|
|
610 | (1) |
|
System.in, System out, and System.err |
|
|
611 | (2) |
|
|
613 | (4) |
|
Programming with the File Class |
|
|
613 | (4) |
|
|
617 | (19) |
|
Writing Simple Data to a Binary File |
|
|
618 | (4) |
|
|
622 | (1) |
|
Reading Simple Data from a Binary File |
|
|
623 | (5) |
|
Checking for the End of a Binary File |
|
|
628 | (2) |
|
PitFall: Checking for the End of a File in the Wrong Way |
|
|
629 | (1) |
|
|
630 | (1) |
|
The Serializable Interface |
|
|
631 | (3) |
|
PitFall: Mixing Class Types in the Same File |
|
|
634 | (1) |
|
Array Objects in Binary Files |
|
|
634 | (2) |
|
10.5 Random Access To Binary Files |
|
|
636 | (15) |
|
Reading and Writing to the Same File |
|
|
636 | (6) |
|
PitFall: RandomAccessFile Need Not Start Empty |
|
|
642 | (1) |
|
|
642 | (1) |
|
Answers to Self-Test Exercises |
|
|
643 | (4) |
|
|
647 | (4) |
Chapter 11 Recursion |
|
651 | (42) |
|
11.1 Recursive Void Methods |
|
|
653 | (12) |
|
Example: Vertical Numbers |
|
|
653 | (3) |
|
|
656 | (3) |
|
A Closer Look at Recursion |
|
|
659 | (3) |
|
PitFall: Infinite Recursion |
|
|
661 | (1) |
|
|
662 | (2) |
|
|
664 | (1) |
|
Recursion versus Iteration |
|
|
664 | (1) |
|
11.2 Recursive Methods That Return A Value |
|
|
665 | (6) |
|
General Form for a Recursive Method That Returns a Value |
|
|
666 | (1) |
|
EXAMPLE: Another Powers Method |
|
|
666 | (5) |
|
11.3 Thinking Recursively |
|
|
671 | (22) |
|
Recursive Design Techniques |
|
|
671 | (1) |
|
|
672 | (6) |
|
Efficiency of Binary Search |
|
|
678 | (5) |
|
|
680 | (3) |
|
|
683 | (1) |
|
Answers to Self-Test Exercises |
|
|
683 | (5) |
|
|
688 | (5) |
Chapter 12 UML and Patterns |
|
693 | (22) |
|
|
694 | (5) |
|
|
695 | (1) |
|
|
695 | (1) |
|
|
696 | (1) |
|
|
696 | (2) |
|
|
698 | (1) |
|
|
699 | (16) |
|
|
699 | (1) |
|
The Model-View-Controller Pattern |
|
|
700 | (7) |
|
Example: A Sorting Pattern |
|
|
701 | (6) |
|
Restrictions on the Sorting Pattern |
|
|
707 | (1) |
|
Efficiency of the Sorting Pattern |
|
|
707 | (1) |
|
Tip: Pragmatics and Patterns |
|
|
708 | (1) |
|
|
708 | (1) |
|
|
709 | (1) |
|
Answers to Self-Test Exercises |
|
|
709 | (2) |
|
|
711 | (4) |
Chapter 13 Interfaces and Inner Classes |
|
715 | (48) |
|
|
717 | (21) |
|
|
717 | (2) |
|
Abstract Classes Implementing Interfaces |
|
|
719 | (1) |
|
|
719 | (4) |
|
PitFall: Interface Semantics Are Not Enforced |
|
|
721 | (2) |
|
|
723 | (6) |
|
Example: Using the Comparable Interface |
|
|
724 | (5) |
|
Defined Constants in Interfaces |
|
|
729 | (4) |
|
PitFall: Inconsistent Interfaces |
|
|
730 | (3) |
|
The Serializable Interface |
|
|
733 | (1) |
|
|
733 | (5) |
|
13.2 Simple Uses Of Inner Classes |
|
|
738 | (6) |
|
|
738 | (5) |
|
Tip: Inner and Outer Classes Have Access to Each Other's Private Members |
|
|
739 | (1) |
|
Example: A Bank Account Class |
|
|
739 | (4) |
|
The .class File for an Inner Class |
|
|
743 | (1) |
|
PitFall: Other Uses of Inner Classes |
|
|
744 | (1) |
|
13.3 More About Inner Classes |
|
|
744 | (19) |
|
|
744 | (1) |
|
|
745 | (4) |
|
Tip: Referring to a Method of the Outer Class |
|
|
747 | (2) |
|
|
749 | (1) |
|
Inner Classes and Inheritance |
|
|
749 | (1) |
|
|
750 | (3) |
|
Tip: Why Use Inner Classes? |
|
|
752 | (1) |
|
|
753 | (1) |
|
Answers to Self-Test Exercises |
|
|
753 | (5) |
|
|
758 | (5) |
Chapter 14 Generics and the ArrayList Class |
|
763 | (44) |
|
|
765 | (17) |
|
Using the ArrayList Class |
|
|
766 | (5) |
|
Tip: Summary of Adding to an ArrayList |
|
|
770 | (1) |
|
Methods in the Class ArrayList |
|
|
771 | (3) |
|
|
774 | (7) |
|
|
777 | (3) |
|
Tip: Use trimToSize to Save Memory |
|
|
780 | (1) |
|
PitFall: The clone Method Makes a Shallow Copy |
|
|
780 | (1) |
|
|
781 | (1) |
|
Parameterized Classes and Generics |
|
|
782 | (1) |
|
PitFall: Nonparameterized ArrayList and Vector Classes |
|
|
782 | (1) |
|
|
782 | (25) |
|
|
783 | (10) |
|
Tip: Compile with the -xlint Option |
|
|
785 | (1) |
|
Example: A Generic Class for Ordered Pairs |
|
|
785 | (3) |
|
PitFall: A Generic Constructor Name Has No Type Parameter |
|
|
788 | (1) |
|
PitFall: You Cannot Plug in a Primitive Type for a Type Parameter |
|
|
789 | (1) |
|
PitFall: A Type Parameter Cannot Be Used Everywhere a Type Name Can Be Used |
|
|
789 | (1) |
|
PitFall: An Instantiation of a Generic Class Cannot be an Array Base Type |
|
|
790 | (1) |
|
Tip: A Class Definition Can Have More Than One Type Parameter |
|
|
791 | (1) |
|
PitFall: A Generic Class Cannot Be an Exception Class |
|
|
792 | (1) |
|
Bounds for Type Parameters |
|
|
793 | (3) |
|
|
796 | (1) |
|
|
796 | (2) |
|
Inheritance with Generic Classes |
|
|
798 | (2) |
|
|
800 | (1) |
|
Answers to Self-Test Exercises |
|
|
800 | (3) |
|
|
803 | (4) |
Chapter 15 Linked Data Structures |
|
807 | (96) |
|
|
810 | (20) |
|
Example: A Simple Linked List Class |
|
|
810 | (4) |
|
Working with Linked Lists |
|
|
814 | (6) |
|
|
819 | (1) |
|
|
820 | (8) |
|
Example: A Generic Linked List |
|
|
823 | (5) |
|
PitFall: Using Node Instead of Node<T> |
|
|
828 | (1) |
|
The equals Method for Linked Lists |
|
|
828 | (2) |
|
15.2 Copy Constructors And The Clone Method |
|
|
830 | (11) |
|
Simple Copy Constructors and clone Methods |
|
|
830 | (1) |
|
|
831 | (10) |
|
PitFall: The clone Method Is Protected in object |
|
|
833 | (1) |
|
Tip: Use a Type Parameter Bound for a Better clone |
|
|
834 | (4) |
|
Example: A Linked List with a Deep Copy clone Method |
|
|
838 | (3) |
|
Tip: Cloning Is an "All or Nothing" Affair |
|
|
841 | (1) |
|
|
841 | (11) |
|
Defining an Iterator Class |
|
|
842 | (5) |
|
Adding and Deleting Nodes |
|
|
847 | (5) |
|
15.4 Variations On A Linked List |
|
|
852 | (20) |
|
|
852 | (9) |
|
|
861 | (2) |
|
|
863 | (3) |
|
Running Times and Big-O Notation |
|
|
866 | (5) |
|
Efficiency of Linked Lists |
|
|
871 | (1) |
|
15.5 Hash Tables With Chaining |
|
|
872 | (5) |
|
A Hash Function for Strings |
|
|
873 | (3) |
|
Efficiency of Hash Tables |
|
|
876 | (1) |
|
|
877 | (7) |
|
Fundamental Set Operations |
|
|
878 | (5) |
|
Efficiency of Sets Using Linked Lists |
|
|
883 | (1) |
|
|
884 | (19) |
|
|
884 | (8) |
|
Example: A Binary Search Tree Class |
|
|
887 | (5) |
|
Efficiency of Binary Search Trees |
|
|
892 | (1) |
|
|
893 | (1) |
|
Answers to Self-Test Exercises |
|
|
894 | (5) |
|
|
899 | (4) |
Chapter 16 Collections, Maps and Iterators |
|
903 | (46) |
|
|
904 | (21) |
|
|
906 | (1) |
|
|
906 | (8) |
|
PitFall: Optional Operations |
|
|
912 | (1) |
|
Tip: Dealing with All Those Exceptions |
|
|
913 | (1) |
|
Concrete Collection Classes |
|
|
914 | (10) |
|
Differences between ArrayList<T> and Vector<T> |
|
|
924 | (1) |
|
Nonparameterized Version of the Collection Framework |
|
|
924 | (1) |
|
PitFall: Omitting the <T> |
|
|
925 | (1) |
|
|
925 | (7) |
|
|
928 | (4) |
|
|
932 | (17) |
|
|
932 | (1) |
|
The Iterator<T> Interface |
|
|
932 | (4) |
|
Tip: For-Each Loops as Iterators |
|
|
935 | (1) |
|
|
936 | (5) |
|
PitFall: next Can Return a Reference |
|
|
938 | (2) |
|
Tip: Defining Your Own Iterator Classes |
|
|
940 | (1) |
|
|
941 | (1) |
|
Answers to Self-Test Exercises |
|
|
941 | (1) |
|
|
942 | (7) |
Chapter 17 Swing I |
|
949 | (76) |
|
17.1 Event-Driven Programming |
|
|
951 | (1) |
|
|
951 | (1) |
|
17.2 Buttons, Events, And Other Swing Basics |
|
|
952 | (18) |
|
|
953 | (5) |
|
PitFall: Forgetting to Program the Close-Window Button |
|
|
958 | (1) |
|
|
959 | (1) |
|
Action Listeners and Action Events |
|
|
960 | (6) |
|
PitFall: Changing the Heading for actionPerformed |
|
|
962 | (1) |
|
Tip: Ending a Swing Program |
|
|
962 | (1) |
|
Example: A Better Version of Our First Swing GUI |
|
|
963 | (3) |
|
|
966 | (1) |
|
|
967 | (3) |
|
Example: A GUI with a Label and Color |
|
|
968 | (2) |
|
17.3 Containers And Layout Managers |
|
|
970 | (19) |
|
|
971 | (3) |
|
|
974 | (1) |
|
|
975 | (4) |
|
|
979 | (5) |
|
Example: A Tricolor Built with Panels |
|
|
980 | (4) |
|
|
984 | (4) |
|
Tip: Code a GUI's Look and Actions Separately |
|
|
987 | (1) |
|
The Model-View-Controller Pattern |
|
|
988 | (1) |
|
|
989 | (12) |
|
Example: A GUI with a Menu |
|
|
989 | (1) |
|
Menus, Menu Items, and Menu Bars |
|
|
989 | (5) |
|
|
994 | (1) |
|
|
994 | (3) |
|
The setActionCommand Method |
|
|
997 | (1) |
|
Listeners as Inner Classes |
|
|
998 | (3) |
|
17.5 Text Fields And Text Areas |
|
|
1001 | (24) |
|
Text Areas and Text Fields |
|
|
1002 | (7) |
|
Tip: Labeling a Text Field |
|
|
1008 | (1) |
|
Tip: Inputting and Outputting Numbers |
|
|
1008 | (1) |
|
|
1009 | (5) |
|
|
1014 | (1) |
|
Answers to Self-Test Exercises |
|
|
1015 | (6) |
|
|
1021 | (4) |
Chapter 18 Swing II |
|
1025 | (62) |
|
|
1026 | (8) |
|
Example: A Window Listener Inner Class |
|
|
1028 | (3) |
|
|
1031 | (1) |
|
PitFall: Forgetting to Invoke setDefaultCloseOperation |
|
|
1032 | (1) |
|
|
1032 | (2) |
|
18.2 Icons And Scroll Bars |
|
|
1034 | (15) |
|
|
1034 | (6) |
|
|
1040 | (9) |
|
Example: Components with Changing Visibility |
|
|
1045 | (4) |
|
|
1049 | (17) |
|
Coordinate System for Graphics Objects |
|
|
1049 | (1) |
|
The Method paint and the Class Graphics |
|
|
1050 | (3) |
|
|
1053 | (1) |
|
|
1053 | (6) |
|
|
1059 | (1) |
|
paintComponent for Panels |
|
|
1060 | (1) |
|
Action Drawings and repaint |
|
|
1060 | (6) |
|
Some More Details on Updating a GUI |
|
|
1066 | (1) |
|
|
1066 | (7) |
|
Specifying a Drawing Color |
|
|
1067 | (1) |
|
|
1068 | (2) |
|
PitFall: Using doubles to Define a Color |
|
|
1069 | (1) |
|
The JColorChooser Dialog Window |
|
|
1070 | (3) |
|
18.5 Fonts And The Drawstring Method |
|
|
1073 | (14) |
|
|
1073 | (3) |
|
|
1076 | (3) |
|
|
1079 | (1) |
|
Answers to Self-Test Exercises |
|
|
1079 | (4) |
|
|
1083 | (4) |
Chapter 19 Java Never Ends |
|
1087 | (80) |
|
|
1088 | (18) |
|
Example: A Nonresponsive GUI |
|
|
1089 | (1) |
|
|
1089 | (4) |
|
|
1093 | (1) |
|
Fixing a Nonresponsive Program Using Threads |
|
|
1094 | (1) |
|
Example: A Multithreaded Program |
|
|
1094 | (1) |
|
|
1095 | (3) |
|
|
1098 | (3) |
|
Race Conditions and Thread Synchronization |
|
|
1101 | (5) |
|
19.2 Networking With Stream Sockets |
|
|
1106 | (5) |
|
|
1106 | (4) |
|
|
1110 | (1) |
|
|
1111 | (1) |
|
|
1111 | (2) |
|
|
1112 | (1) |
|
|
1112 | (1) |
|
19.4 JAVA And Database Connections |
|
|
1113 | (13) |
|
|
1113 | (1) |
|
|
1114 | (1) |
|
|
1115 | (11) |
|
19.5 Web Programming With JAVA Server Pages |
|
|
1126 | (14) |
|
Applets, Servlets, and Java Server Pages |
|
|
1126 | (2) |
|
Oracle GlassFish Enterprise Server |
|
|
1128 | (1) |
|
HTML Forms-the Common Gateway Interface |
|
|
1129 | |
|
JSP Declarations, Expressions, Scriptlets, and Directives |
|
|
1123 | (17) |
|
19.6 Introduction To Functional Programming In Java 8 |
|
|
1140 | (8) |
|
19.7 Introduction To JAVAFX |
|
|
1148 | |
|
|
1161 | (3) |
|
Answers to Self-Test Exercises 1162 Programming Projects |
|
|
1164 | |
Chapter 20 Applets and HTML (online at www.pearsonhighered.com/ savitch) |
|
Appendix 1 Keywords |
|
1167 | (2) |
Appendix 2 Precedence and Associativity Rules |
|
1169 | (2) |
Appendix 3 ASCII Character Set |
|
1171 | (2) |
Appendix 4 Format Specifications for printf |
|
1173 | (2) |
Appendix 5 Summary of Classes and Interfaces |
|
1175 | (68) |
Index |
|
1243 | |