| |  | Copyright | iv |
| |  | Deitel® Books, Cyber Classrooms, Complete Training Courses and Web-Based Training Courses published by Prentice Hall | ii |
| |  | Preface | xxv |
| |
|  | Features in Java How to Program, 6/e | xxvi |
| |
|  | Teaching Approach | xxix |
| |
|  | Tour of the Book | xxxiii |
| |
|  | A Tour of the Optional Case Study on Object-Oriented Design with the UML | xliii |
| |
|  | A Tour of the Optional GUI and Graphics Case Study | xlv |
| |
|  | Software Included with Java How to Program, 6/e | xlvi |
| |
|  | Teaching Resources for Java How to Program, 6/e | xlvii |
| |
|  | Java in the Lab | xlvii |
| |
|  | OneKey, CourseCompassSM, WebCT™ and by Blackboard™ | xlix |
| |
|  | Java 2 Multimedia Cyber Classroom, 6/e Through OneKey | l |
| |
|  | PearsonChoices | l |
| |
|  | Computer Science AP Courses | li |
| |
|  | Deitel® Buzz Online Free E-mail Newsletter | li |
| |
|  | Acknowledgments | li |
| |
|  | About the Authors | lv |
| |
|  | About Deitel & Associates, Inc. | lv |
| |  | Before You Begin | lvii |
| |
|  | Software and Other Resources on the CD That Accompanies Java How to Program, Sixth Edition | lvii |
| |
|  | Hardware and Software Requirements to Run JDK 5.0 | lvii |
| |
|  | Copying and Organizing Files | lviii |
| |
|  | Copying the Book Examples from the CD | lviii |
| |
|  | Changing the Read-Only Property of Files | lviii |
| |
|  | Installing the J2SE Development Kit (JDK) | lxii |
| |
|  | Setting the PATH Variable | lxiv |
| |  |
Chapter 1.
Introduction to Computers, the Internet and the World Wide Web | 1 |
| |
|  |
Section 1.1.
Introduction | 2 |
| |
|  |
Section 1.2.
What Is a Computer? | 4 |
| |
|  |
Section 1.3.
Computer Organization | 4 |
| |
|  |
Section 1.4.
Early Operating Systems | 5 |
| |
|  |
Section 1.5.
Personal, Distributed and Client/Server Computing | 6 |
| |
|  |
Section 1.6.
The Internet and the World Wide Web | 6 |
| |
|  |
Section 1.7.
Machine Languages, Assembly Languages and High-Level Languages | 7 |
| |
|  |
Section 1.8.
History of C and C++ | 8 |
| |
|  |
Section 1.9.
History of Java | 9 |
| |
|  |
Section 1.10.
Java Class Libraries | 9 |
| |
|  |
Section 1.11.
FORTRAN, COBOL, Pascal and Ada | 11 |
| |
|  |
Section 1.12.
BASIC, Visual Basic, Visual C++, C# and .NET | 11 |
| |
|  |
Section 1.13.
Typical Java Development Environment | 12 |
| |
|  |
Section 1.14.
Notes about Java and Java How to Program, Sixth Edition | 15 |
| |
|  |
Section 1.15.
Test-Driving a Java Application | 16 |
| |
|  |
Section 1.16.
Software Engineering Case Study: Introduction to Object Technology and the UML (Required) | 21 |
| |
|  |
Section 1.17.
Wrap-Up | 26 |
| |
|  |
Section 1.18.
Web Resources | 26 |
| |
|  | Summary | 28 |
| |
|  | Terminology | 30 |
| |
|  | Self-Review Exercises | 32 |
| |
|  | Answers to Self-Review Exercises | 32 |
| |
|  | Exercises | 33 |
| |  |
Chapter 2.
Introduction to Java Applications | 35 |
| |
|  |
Section 2.1.
Introduction | 36 |
| |
|  |
Section 2.2.
First Program in Java: Printing a Line of Text | 36 |
| |
|  |
Section 2.3.
Modifying Our First Java Program | 43 |
| |
|  |
Section 2.4.
Displaying Text with printf | 45 |
| |
|  |
Section 2.5.
Another Java Application: Adding Integers | 47 |
| |
|  |
Section 2.6.
Memory Concepts | 51 |
| |
|  |
Section 2.7.
Arithmetic | 52 |
| |
|  |
Section 2.8.
Decision Making: Equality and Relational Operators | 56 |
| |
|  |
Section 2.9.
(Optional) Software Engineering Case Study: Examining the Requirements Document | 60 |
| |
|  |
Section 2.10.
Wrap-Up | 69 |
| |
|  | Summary | 70 |
| |
|  | Terminology | 73 |
| |
|  | Self-Review Exercises | 74 |
| |
|  | Answers to Self-Review Exercises | 75 |
| |
|  | Exercises | 77 |
| |  |
Chapter 3.
Introduction to Classes and Objects | 81 |
| |
|  |
Section 3.1.
Introduction | 82 |
| |
|  |
Section 3.2.
Classes, Objects, Methods and Instance Variables | 82 |
| |
|  |
Section 3.3.
Declaring a Class with a Method and Instantiating an Object of a Class | 84 |
| |
|  |
Section 3.4.
Declaring a Method with a Parameter | 88 |
| |
|  |
Section 3.5.
Instance Variables, set Methods and get Methods | 91 |
| |
|  |
Section 3.6.
Primitive Types vs. Reference Types | 96 |
| |
|  |
Section 3.7.
Initializing Objects with Constructors | 97 |
| |
|  |
Section 3.8.
Floating-Point Numbers and Type double | 100 |
| |
|  |
Section 3.9.
(Optional) GUI and Graphics Case Study: Using Dialog Boxes | 104 |
| |
|  |
Section 3.10.
(Optional) Software Engineering Case Study: Identifying the Classes in a Requirements Document | 107 |
| |
|  |
Section 3.11.
Wrap-Up | 114 |
| |
|  | Summary | 115 |
| |
|  | Terminology | 119 |
| |
|  | Self-Review Exercises | 119 |
| |
|  | Answers to Self-Review Exercises | 120 |
| |
|  | Exercises | 121 |
| |  |
Chapter 4.
Control Statements: Part I | 123 |
| |
|  |
Section 4.1.
Introduction | 124 |
| |
|  |
Section 4.2.
Algorithms | 124 |
| |
|  |
Section 4.3.
Pseudocode | 125 |
| |
|  |
Section 4.4.
Control Structures | 125 |
| |
|  |
Section 4.5.
if Single-Selection Statement | 128 |
| |
|  |
Section 4.6.
if...else Double-Selection Statement | 129 |
| |
|  |
Section 4.7.
while Repetition Statement | 134 |
| |
|  |
Section 4.8.
Formulating Algorithms: Counter-Controlled Repetition | 135 |
| |
|  |
Section 4.9.
Formulating Algorithms: Sentinel-Controlled Repetition | 140 |
| |
|  |
Section 4.10.
Formulating Algorithms: Nested Control Statements | 148 |
| |
|  |
Section 4.11.
Compound Assignment Operators | 153 |
| |
|  |
Section 4.12.
Increment and Decrement Operators | 154 |
| |
|  |
Section 4.13.
Primitive Types | 156 |
| |
|  |
Section 4.14.
(Optional) GUI and Graphics Case Study: Creating Simple Drawings | 157 |
| |
|  |
Section 4.15.
(Optional) Software Engineering Case Study: Identifying Class Attributes | 162 |
| |
|  |
Section 4.16.
Wrap-Up | 166 |
| |
|  | Summary | 167 |
| |
|  | Terminology | 168 |
| |
|  | Self-Review Exercises | 169 |
| |
|  | Answers to Self-Review Exercises | 171 |
| |
|  | Exercises | 172 |
| |  |
Chapter 5.
Control Statements: Part 2 | 179 |
| |
|  |
Section 5.1.
Introduction | 180 |
| |
|  |
Section 5.2.
Essentials of Counter-Controlled Repetition | 180 |
| |
|  |
Section 5.3.
for Repetition Statement | 182 |
| |
|  |
Section 5.4.
Examples Using the for Statement | 186 |
| |
|  |
Section 5.5.
do...while Repetition Statement | 191 |
| |
|  |
Section 5.6.
switch Multiple-Selection Statement | 192 |
| |
|  |
Section 5.7.
break and continue Statements | 200 |
| |
|  |
Section 5.8.
Logical Operators | 202 |
| |
|  |
Section 5.9.
Structured Programming Summary | 208 |
| |
|  |
Section 5.10.
(Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals | 213 |
| |
|  |
Section 5.11.
(Optional) Software Engineering Case Study: Identifying Objects' States and Activities | 216 |
| |
|  |
Section 5.12.
Wrap-Up | 220 |
| |
|  | Summary | 221 |
| |
|  | Terminology | 223 |
| |
|  | Self-Review Exercises | 224 |
| |
|  | Answers to Self-Review Exercises | 225 |
| |
|  | Exercises | 226 |
| |  |
Chapter 6.
Methods: A Deeper Look | 230 |
| |
|  |
Section 6.1.
Introduction | 231 |
| |
|  |
Section 6.2.
Program Modules in Java | 232 |
| |
|  |
Section 6.3.
static Methods, static Fields and Class Math | 233 |
| |
|  |
Section 6.4.
Declaring Methods with Multiple Parameters | 236 |
| |
|  |
Section 6.5.
Notes on Declaring and Using Methods | 240 |
| |
|  |
Section 6.6.
Method Call Stack and Activation Records | 241 |
| |
|  |
Section 6.7.
Argument Promotion and Casting | 241 |
| |
|  |
Section 6.8.
Java API Packages | 243 |
| |
|  |
Section 6.9.
Case Study: Random-Number Generation | 245 |
| |
|  |
Section 6.10.
Case Study: A Game of Chance (Introducing Enumerations) | 250 |
| |
|  |
Section 6.11.
Scope of Declarations | 255 |
| |
|  |
Section 6.12.
Method Overloading | 257 |
| |
|  |
Section 6.13.
(Optional) GUI and Graphics Case Study: Colors and Filled Shapes | 261 |
| |
|  |
Section 6.14.
(Optional) Software Engineering Case Study: Identifying Class Operations | 263 |
| |
|  |
Section 6.15.
Wrap-Up | 271 |
| |
|  | Summary | 271 |
| |
|  | Terminology | 274 |
| |
|  | Self-Review Exercises | 275 |
| |
|  | Answers to Self-Review Exercises | 277 |
| |
|  | Exercises | 279 |
| |  |
Chapter 7.
Arrays | 285 |
| |
|  |
Section 7.1.
Introduction | 286 |
| |
|  |
Section 7.2.
Arrays | 286 |
| |
|  |
Section 7.3.
Declaring and Creating Arrays | 288 |
| |
|  |
Section 7.4.
Examples Using Arrays | 289 |
| |
|  |
Section 7.5.
Case Study: Card Shuffling and Dealing Simulation | 298 |
| |
|  |
Section 7.6.
Enhanced for Statement | 301 |
| |
|  |
Section 7.7.
Passing Arrays to Methods | 303 |
| |
|  |
Section 7.8.
Case Study: Class GradeBook Using an Array to Store Grades | 307 |
| |
|  |
Section 7.9.
Multidimensional Arrays | 311 |
| |
|  |
Section 7.10.
Case Study: Class GradeBook Using a Two-Dimensional Array | 316 |
| |
|  |
Section 7.11.
Variable-Length Argument Lists | 322 |
| |
|  |
Section 7.12.
Using Command-Line Arguments | 323 |
| |
|  |
Section 7.13.
(Optional) GUI and Graphics Case Study: Drawing Arcs | 325 |
| |
|  |
Section 7.14.
(Optional) Software Engineering Case Study: Collaboration Among Objects | 328 |
| |
|  |
Section 7.15.
Wrap-Up | 336 |
| |
|  | Summary | 337 |
| |
|  | Terminology | 339 |
| |
|  | Self-Review Exercises | 339 |
| |
|  | Answers to Self-Review Exercises | 340 |
| |
|  | Exercises | 341 |
| |
|  | Special Section: Building Your Own Computer | 350 |
| |  |
Chapter 8.
Classes and Objects: A Deeper Look | 357 |
| |
|  |
Section 8.1.
Introduction | 358 |
| |
|  |
Section 8.2.
Time Class Case Study | 359 |
| |
|  |
Section 8.3.
Controlling Access to Members | 362 |
| |
|  |
Section 8.4.
Referring to the Current Object's Members with the this Reference | 363 |
| |
|  |
Section 8.5.
Time Class Case Study: Overloaded Constructors | 366 |
| |
|  |
Section 8.6.
Default and No-Argument Constructors | 371 |
| |
|  |
Section 8.7.
Notes on Set and Get Methods | 372 |
| |
|  |
Section 8.8.
Composition | 373 |
| |
|  |
Section 8.9.
Enumerations | 376 |
| |
|  |
Section 8.10.
Garbage Collection and Method finalize | 379 |
| |
|  |
Section 8.11.
static Class Members | 380 |
| |
|  |
Section 8.12.
static Import | 385 |
| |
|  |
Section 8.13.
final Instance Variables | 386 |
| |
|  |
Section 8.14.
Software Reusability | 388 |
| |
|  |
Section 8.15.
Data Abstraction and Encapsulation | 389 |
| |
|  |
Section 8.16.
Time Class Case Study: Creating Packages | 390 |
| |
|  |
Section 8.17.
Package Access | 396 |
| |
|  |
Section 8.18.
(Optional) GUI and Graphics Case Study: Using Objects with Graphics | 396 |
| |
|  |
Section 8.19.
(Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System | 401 |
| |
|  |
Section 8.20.
Wrap-Up | 406 |
| |
|  | Summary | 407 |
| |
|  | Terminology | 410 |
| |
|  | Self-Review Exercises | 410 |
| |
|  | Answers to Self-Review Exercises | 411 |
| |
|  | Exercises | 411 |
| |  |
Chapter 9.
Object-Oriented Programming: Inheritance | 415 |
| |
|  |
Section 9.1.
Introduction | 416 |
| |
|  |
Section 9.2.
Superclasses and Subclasses | 417 |
| |
|  |
Section 9.3.
protected Members | 419 |
| |
|  |
Section 9.4.
Relationship between Superclasses and Subclasses | 420 |
| |
|  |
Section 9.5.
Constructors in Subclasses | 444 |
| |
|  |
Section 9.6.
Software Engineering with Inheritance | 450 |
| |
|  |
Section 9.7.
Object Class | 451 |
| |
|  |
Section 9.8.
(Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels | 453 |
| |
|  |
Section 9.9.
Wrap-Up | 455 |
| |
|  | Summary | 455 |
| |
|  | Terminology | 456 |
| |
|  | Self-Review Exercises | 457 |
| |
|  | Answers to Self-Review Exercises | 457 |
| |
|  | Exercises | 458 |
| |  |
Chapter 10.
Object-Oriented Programming: Polymorphism | 459 |
| |
|  |
Section 10.1.
Introduction | 460 |
| |
|  |
Section 10.2.
Polymorphism Examples | 462 |
| |
|  |
Section 10.3.
Demonstrating Polymorphic Behavior | 463 |
| |
|  |
Section 10.4.
Abstract Classes and Methods | 466 |
| |
|  |
Section 10.5.
Case Study: Payroll System Using Polymorphism | 468 |
| |
|  |
Section 10.6.
final Methods and Classes | 483 |
| |
|  |
Section 10.7.
Case Study: Creating and Using Interfaces | 484 |
| |
|  |
Section 10.8.
(Optional) GUI and Graphics Case Study: Drawing with Polymorphism | 496 |
| |
|  |
Section 10.9.
(Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System | 498 |
| |
|  |
Section 10.10.
Wrap-Up | 506 |
| |
|  | Summary | 506 |
| |
|  | Terminology | 507 |
| |
|  | Self-Review Exercises | 507 |
| |
|  | Answers to Self-Review Exercises | 508 |
| |
|  | Exercises | 508 |
| |  |
Chapter 11.
GUI Components: Part 1 | 510 |
| |
|  |
Section 11.1.
Introduction | 511 |
| |
|  |
Section 11.2.
Simple GUI-Based Input/Output with JOptionPane | 512 |
| |
|  |
Section 11.3.
Overview of Swing Components | 515 |
| |
|  |
Section 11.4.
Displaying Text and Images in a Window | 518 |
| |
|  |
Section 11.5.
Text Fields and an Introduction to Event Handling with Nested Classes | 522 |
| |
|  |
Section 11.6.
Common GUI Event Types and Listener Interfaces | 529 |
| |
|  |
Section 11.7.
How Event Handling Works | 530 |
| |
|  |
Section 11.8.
JButton | 533 |
| |
|  |
Section 11.9.
Buttons that Maintain State | 536 |
| |
|  |
Section 11.10.
JComboBox and Using an Anonymous Inner Class for Event Handling | 543 |
| |
|  |
Section 11.11.
JList | 546 |
| |
|  |
Section 11.12.
Multiple-Selection Lists | 549 |
| |
|  |
Section 11.13.
Mouse Event Handling | 551 |
| |
|  |
Section 11.14.
Adapter Classes | 556 |
| |
|  |
Section 11.15.
JPanel Subclass for Drawing with the Mouse | 559 |
| |
|  |
Section 11.16.
Key-Event Handling | 563 |
| |
|  |
Section 11.17.
Layout Managers | 567 |
| |
|  |
Section 11.18.
Using Panels to Manage More Complex Layouts | 576 |
| |
|  |
Section 11.19.
JTextArea | 578 |
| |
|  |
Section 11.20.
Wrap-Up | 581 |
| |
|  | Summary | 581 |
| |
|  | Terminology | 587 |
| |
|  | Self-Review Exercises | 589 |
| |
|  | Answers to Self-Review Exercises | 590 |
| |
|  | Exercises | 590 |
| |  |
Chapter 12.
Graphics and Java 2D™ | 595 |
| |
|  |
Section 12.1.
Introduction | 596 |
| |
|  |
Section 12.2.
Graphics Contexts and Graphics Objects | 598 |
| |
|  |
Section 12.3.
Color Control | 599 |
| |
|  |
Section 12.4.
Font Control | 606 |
| |
|  |
Section 12.5.
Drawing Lines, Rectangles and Ovals | 611 |
| |
|  |
Section 12.6.
Drawing Arcs | 616 |
| |
|  |
Section 12.7.
Drawing Polygons and Polylines | 618 |
| |
|  |
Section 12.8.
Java 2D API | 622 |
| |
|  |
Section 12.9.
Wrap-Up | 629 |
| |
|  | Summary | 629 |
| |
|  | Terminology | 631 |
| |
|  | Self-Review Exercises | 632 |
| |
|  | Answers to Self-Review Exercises | 633 |
| |
|  | Exercises | 633 |
| |  |
Chapter 13.
Exception Handling | 638 |
| |
|  |
Section 13.1.
Introduction | 639 |
| |
|  |
Section 13.2.
Exception-Handling Overview | 640 |
| |
|  |
Section 13.3.
Example: Divide By Zero Without Exception Handling | 641 |
| |
|  |
Section 13.4.
Example: Handling ArithmeticExceptions and InputMismatchExceptions | 643 |
| |
|  |
Section 13.5.
When to Use Exception Handling | 648 |
| |
|  |
Section 13.6.
Java Exception Hierarchy | 649 |
| |
|  |
Section 13.7.
finally block | 652 |
| |
|  |
Section 13.8.
Stack Unwinding | 656 |
| |
|  |
Section 13.9.
printStackTrace, getStackTrace and getMessage | 658 |
| |
|  |
Section 13.10.
Chained Exceptions | 660 |
| |
|  |
Section 13.11.
Declaring New Exception Types | 662 |
| |
|  |
Section 13.12.
Preconditions and Postconditions | 663 |
| |
|  |
Section 13.13.
Assertions | 664 |
| |
|  |
Section 13.14.
Wrap-Up | 666 |
| |
|  | Summary | 666 |
| |
|  | Terminology | 668 |
| |
|  | Self-Review Exercises | 669 |
| |
|  | Answers to Self-Review Exercises | 670 |
| |
|  | Exercises | 670 |
| |  |
Chapter 14.
Files and Streams | 672 |
| |
|  |
Section 14.1.
Introduction | 673 |
| |
|  |
Section 14.2.
Data Hierarchy | 674 |
| |
|  |
Section 14.3.
Files and Streams | 675 |
| |
|  |
Section 14.4.
Class File | 678 |
| |
|  |
Section 14.5.
Sequential-Access Text Files | 682 |
| |
|  |
Section 14.6.
Object Serialization | 697 |
| |
|  |
Section 14.7.
Random-Access Files | 706 |
| |
|  |
Section 14.8.
Additional java.io Classes | 727 |
| |
|  |
Section 14.9.
Opening Files with JFileChooser | 729 |
| |
|  |
Section 14.10.
Wrap-Up | 733 |
| |
|  | Summary | 733 |
| |
|  | Terminology | 735 |
| |
|  | Self-Review Exercises | 737 |
| |
|  | Answers to Self-Review Exercises | 738 |
| |
|  | Exercises | 739 |
| |  |
Chapter 15.
Recursion | 744 |
| |
|  |
Section 15.1.
Introduction | 745 |
| |
|  |
Section 15.2.
Recursion Concepts | 745 |
| |
|  |
Section 15.3.
Example Using Recursion: Factorials | 747 |
| |
|  |
Section 15.4.
Example Using Recursion: Fibonacci Series | 750 |
| |
|  |
Section 15.5.
Recursion and the Method Call Stack | 753 |
| |
|  |
Section 15.6.
Recursion vs. Iteration | 754 |
| |
|  |
Section 15.7.
String Permutations | 756 |
| |
|  |
Section 15.8.
Towers of Hanoi | 761 |
| |
|  |
Section 15.9.
Fractals | 763 |
| |
|  |
Section 15.10.
Recursive Backtracking | 774 |
| |
|  |
Section 15.11.
Wrap-Up | 775 |
| |
|  |
Section 15.12.
Internet and Web Resources | 775 |
| |
|  | Summary | 776 |
| |
|  | Terminology | 778 |
| |
|  | Self-Review Exercises | 779 |
| |
|  | Answers to Self-Review Exercises | 780 |
| |
|  | Exercises | 780 |
| |  |
Chapter 16.
Searching and Sorting | 785 |
| |
|  |
Section 16.1.
Introduction | 786 |
| |
|  |
Section 16.2.
Searching Algorithms | 786 |
| |
|  |
Section 16.3.
Sorting Algorithms | 796 |
| |
|  |
Section 16.4.
Invariants | 810 |
| |
|  |
Section 16.5.
Wrap-up | 812 |
| |
|  | Summary | 812 |
| |
|  | Terminology | 814 |
| |
|  | Self-Review Exercises | 814 |
| |
|  | Answers to Self-Review Exercises | 814 |
| |
|  | Exercises | 814 |
| |  |
Chapter 17.
Data Structures | 817 |
| |
|  |
Section 17.1.
Introduction | 818 |
| |
|  |
Section 17.2.
Type-Wrapper Classes for Primitive Types | 819 |
| |
|  |
Section 17.3.
Autoboxing and Auto-Unboxing | 819 |
| |
|  |
Section 17.4.
Self-Referential Classes | 820 |
| |
|  |
Section 17.5.
Dynamic Memory Allocation | 821 |
| |
|  |
Section 17.6.
Linked Lists | 821 |
| |
|  |
Section 17.7.
Stacks | 832 |
| |
|  |
Section 17.8.
Queues | 836 |
| |
|  |
Section 17.9.
Trees | 838 |
| |
|  |
Section 17.10.
Wrap-Up | 845 |
| |
|  | Summary | 846 |
| |
|  | Terminology | 847 |
| |
|  | Self-Review Exercises | 848 |
| |
|  | Answers to Self-Review Exercises | 849 |
| |
|  | Exercises | 850 |
| |
|  | Special Section: Building Your Own Compiler | 855 |
| |  |
Chapter 18.
Generics | 869 |
| |
|  |
Section 18.1.
Introduction | 870 |
| |
|  |
Section 18.2.
Motivation for Generic Methods | 871 |
| |
|  |
Section 18.3.
Generic Methods: Implementation and Compile-Time Translation | 873 |
| |
|  |
Section 18.4.
Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type | 876 |
| |
|  |
Section 18.5.
Overloading Generic Methods | 879 |
| |
|  |
Section 18.6.
Generic Classes | 879 |
| |
|  |
Section 18.7.
Raw Types | 890 |
| |
|  |
Section 18.8.
Wildcards in Methods That Accept Type Parameters | 891 |
| |
|  |
Section 18.9.
Generics and Inheritance: Notes | 898 |
| |
|  |
Section 18.10.
Wrap-Up | 898 |
| |
|  |
Section 18.11.
Internet and Web Resources | 899 |
| |
|  | Summary | 899 |
| |
|  | Terminology | 901 |
| |
|  | Self-Review Exercises | 901 |
| |
|  | Answers to Self-Review Exercises | 902 |
| |
|  | Exercises | 902 |
| |  |
Chapter 19.
Collections | 904 |
| |
|  |
Section 19.1.
Introduction | 905 |
| |
|  |
Section 19.2.
Collections Overview | 906 |
| |
|  |
Section 19.3.
Class Arrays | 907 |
| |
|  |
Section 19.4.
Interface Collection and Class Collections | 910 |
| |
|  |
Section 19.5.
Lists | 911 |
| |
|  |
Section 19.6.
Collections Algorithms | 922 |
| |
|  |
Section 19.7.
Stack Class of Package java.util | 935 |
| |
|  |
Section 19.8.
Class PriorityQueue and Interface Queue | 938 |
| |
|  |
Section 19.9.
Sets | 939 |
| |
|  |
Section 19.10.
Maps | 942 |
| |
|  |
Section 19.11.
Properties Class | 946 |
| |
|  |
Section 19.12.
Synchronized Collections | 949 |
| |
|  |
Section 19.13.
Unmodifiable Collections | 950 |
| |
|  |
Section 19.14.
Abstract Implementations | 950 |
| |
|  |
Section 19.15.
Wrap-Up | 951 |
| |
|  | Summary | 951 |
| |
|  | Terminology | 954 |
| |
|  | Self-Review Exercises | 955 |
| |
|  | Answers to Self-Review Exercises | 955 |
| |
|  | Exercises | 956 |
| |  |
Chapter 20.
Introduction to Java Applets | 958 |
| |
|  |
Section 20.1.
Introduction | 959 |
| |
|  |
Section 20.2.
Sample Applets Provided with the JDK | 959 |
| |
|  |
Section 20.3.
Simple Java Applet: Drawing a String | 964 |
| |
|  |
Section 20.4.
Applet Life-Cycle Methods | 968 |
| |
|  |
Section 20.5.
Initializing an Instance Variable with Method init | 970 |
| |
|  |
Section 20.6.
Sandbox Security Model | 972 |
| |
|  |
Section 20.7.
Internet and Web Resources | 972 |
| |
|  |
Section 20.8.
Wrap-Up | 973 |
| |
|  | Summary | 973 |
| |
|  | Terminology | 975 |
| |
|  | Self-Review Exercises | 975 |
| |
|  | Answers to Self-Review Exercises | 975 |
| |
|  | Exercises | 975 |
| |  |
Chapter 21.
Multimedia: Applets and Applications | 977 |
| |
|  |
Section 21.1.
Introduction | 978 |
| |
|  |
Section 21.2.
Loading, Displaying and Scaling Images | 979 |
| |
|  |
Section 21.3.
Animating a Series of Images | 982 |
| |
|  |
Section 21.4.
Image Maps | 987 |
| |
|  |
Section 21.5.
Loading and Playing Audio Clips | 987 |
| |
|  |
Section 21.6.
Playing Video and Other Media with Java Media Framework | 993 |
| |
|  |
Section 21.7.
Wrap-Up | 997 |
| |
|  |
Section 21.8.
Internet and Web Resources | 998 |
| |
|  | Summary | 999 |
| |
|  | Terminology | 1000 |
| |
|  | Self-Review Exercises | 1001 |
| |
|  | Answers to Self-Review Exercises | 1001 |
| |
|  | Exercises | 1001 |
| |
|  | Special Section: Challenging Multimedia Projects | 1002 |
| |  |
Chapter 22.
GUI Components: Part 2 | 1005 |
| |
|  |
Section 22.1.
Introduction | 1006 |
| |
|  |
Section 22.2.
JSlider | 1006 |
| |
|  |
Section 22.3.
Windows: Additional Notes | 1010 |
| |
|  |
Section 22.4.
Using Menus with Frames | 1011 |
| |
|  |
Section 22.5.
JPopupMenu | 1019 |
| |
|  |
Section 22.6.
Pluggable Look-and-Feel | 1022 |
| |
|  |
Section 22.7.
JDesktopPane and JInternalFrame | 1026 |
| |
|  |
Section 22.8.
JTabbedPane | 1030 |
| |
|  |
Section 22.9.
Layout Managers: BoxLayout and GridBagLayout | 1032 |
| |
|  |
Section 22.10.
Wrap-Up | 1046 |
| |
|  | Summary | 1046 |
| |
|  | Terminology | 1048 |
| |
|  | Self-Review Exercises | 1049 |
| |
|  | Answers to Self-Review Exercises | 1050 |
| |
|  | Exercises | 1050 |
| |  |
Chapter 23.
Multithreading | 1052 |
| |
|  |
Section 23.1.
Introduction | 1053 |
| |
|  |
Section 23.2.
Thread States: Life Cycle of a Thread | 1055 |
| |
|  |
Section 23.3.
Thread Priorities and Thread Scheduling | 1056 |
| |
|  |
Section 23.4.
Creating and Executing Threads | 1058 |
| |
|  |
Section 23.5.
Thread Synchronization | 1062 |
| |
|  |
Section 23.6.
Producer/Consumer Relationship without Synchronization | 1064 |
| |
|  |
Section 23.7.
Producer/Consumer Relationship with Synchronization | 1071 |
| |
|  |
Section 23.8.
Producer/Consumer Relationship: Circular Buffer | 1076 |
| |
|  |
Section 23.9.
Producer/Consumer Relationship: ArrayBlockingQueue | 1084 |
| |
|  |
Section 23.10.
Multithreading with GUI | 1087 |
| |
|  |
Section 23.11.
Other Classes and Interfaces in java.util.concurrent | 1093 |
| |
|  |
Section 23.12.
Monitors and Monitor Locks | 1093 |
| |
|  |
Section 23.13.
Wrap-Up | 1100 |
| |
|  | Summary | 1100 |
| |
|  | Terminology | 1102 |
| |
|  | Self-Review Exercises | 1103 |
| |
|  | Answers to Self-Review Exercises | 1104 |
| |
|  | Exercises | 1104 |
| |  |
Chapter 24.
Networking | 1106 |
| |
|  |
Section 24.1.
Introduction | 1107 |
| |
|  |
Section 24.2.
Manipulating URLs | 1108 |
| |
|  |
Section 24.3.
Reading a File on a Web Server | 1114 |
| |
|  |
Section 24.4.
Establishing a Simple Server Using Stream Sockets | 1117 |
| |
|  |
Section 24.5.
Establishing a Simple Client Using Stream Sockets | 1119 |
| |
|  |
Section 24.6.
Client/Server Interaction with Stream Socket Connections | 1119 |
| |
|  |
Section 24.7.
Connectionless Client/Server Interaction with Datagrams | 1132 |
| |
|  |
Section 24.8.
Client/Server Tic-Tac-Toe Using a Multithreaded Server | 1139 |
| |
|  |
Section 24.9.
Security and the Network | 1154 |
| |
|  |
Section 24.10.
Case Study: DeitelMessenger Server and Client | 1155 |
| |
|  |
Section 24.11.
Wrap-Up | 1181 |
| |
|  | Summary | 1181 |
| |
|  | Terminology | 1183 |
| |
|  | Self-Review Exercises | 1184 |
| |
|  | Answers to Self-Review Exercises | 1185 |
| |
|  | Exercises | 1185 |
| |  |
Chapter 25.
Accessing Databases with JDBC | 1189 |
| |
|  |
Section 25.1.
Introduction | 1190 |
| |
|  |
Section 25.2.
Relational Databases | 1191 |
| |
|  |
Section 25.3.
Relational Database Overview: The books Database | 1192 |
| |
|  |
Section 25.4.
SQL | 1196 |
| |
|  |
Section 25.5.
Instructions to install MySQL and MySQL Connector/J | 1206 |
| |
|  |
Section 25.6.
Instructions on Setting MySQL User Account | 1206 |
| |
|  |
Section 25.7.
Creating Database books in MySQL | 1207 |
| |
|  |
Section 25.8.
Manipulating Databases with JDBC | 1207 |
| |
|  |
Section 25.9.
Stored Procedures | 1224 |
| |
|  |
Section 25.10.
RowSet Interface | 1224 |
| |
|  |
Section 25.11.
Wrap-Up | 1227 |
| |
|  |
Section 25.12.
Internet and Web Resources | 1227 |
| |
|  | Recommended Readings | 1228 |
| |
|  | Summary | 1229 |
| |
|  | Terminology | 1232 |
| |
|  | Self-Review Exercises | 1234 |
| |
|  | Answers to Self-Review Exercises | 1234 |
| |
|  | Exercises | 1234 |
| |  |
Chapter 26.
Servlets | 1236 |
| |
|  |
Section 26.1.
Introduction | 1237 |
| |
|  |
Section 26.2.
Servlet Overview and Architecture | 1239 |
| |
|  |
Section 26.3.
Setting Up the Apache Tomcat Server | 1243 |
| |
|  |
Section 26.4.
Handling HTTP get Requests | 1246 |
| |
|  |
Section 26.5.
Handling HTTP get Requests Containing Data | 1255 |
| |
|  |
Section 26.6.
Handling HTTP post Requests | 1258 |
| |
|  |
Section 26.7.
Redirecting Requests to Other Resources | 1261 |
| |
|  |
Section 26.8.
Multitier Applications: Using JDBC from a Servlet | 1265 |
| |
|  |
Section 26.9.
Welcome Files | 1270 |
| |
|  |
Section 26.10.
Wrap-Up | 1274 |
| |
|  |
Section 26.11.
Internet and Web Resources | 1274 |
| |
|  | Summary | 1275 |
| |
|  | Terminology | 1277 |
| |
|  | Self-Review Exercises | 1277 |
| |
|  | Answers to Self-Review Exercises | 1278 |
| |
|  | Exercises | 1278 |
| |  |
Chapter 27.
JavaServer Pages (JSP) | 1280 |
| |
|  |
Section 27.1.
Introduction | 1281 |
| |
|  |
Section 27.2.
JavaServer Pages Overview | 1282 |
| |
|  |
Section 27.3.
First JSP Example | 1283 |
| |
|  |
Section 27.4.
Implicit Objects | 1285 |
| |
|  |
Section 27.5.
Scripting | 1286 |
| |
|  |
Section 27.6.
Standard Actions | 1291 |
| |
|  |
Section 27.7.
Directives | 1305 |
| |
|  |
Section 27.8.
Case Study: Guest Book | 1309 |
| |
|  |
Section 27.9.
Wrap-Up | 1321 |
| |
|  |
Section 27.10.
Internet and Web Resources | 1321 |
| |
|  | Summary | 1321 |
| |
|  | Terminology | 1323 |
| |
|  | Self-Review Exercises | 1324 |
| |
|  | Answers to Self-Review Exercises | 1325 |
| |
|  | Exercises | 1325 |
| |  |
Chapter 28.
Formatted Output | 1326 |
| |
|  |
Section 28.1.
Introduction | 1327 |
| |
|  |
Section 28.2.
Streams | 1327 |
| |
|  |
Section 28.3.
Formatting Output with printf | 1328 |
| |
|  |
Section 28.4.
Printing Integers | 1328 |
| |
|  |
Section 28.5.
Printing Floating-Point Numbers | 1329 |
| |
|  |
Section 28.6.
Printing Strings and Characters | 1330 |
| |
|  |
Section 28.7.
Printing Dates and Times | 1331 |
| |
|  |
Section 28.8.
Other Conversion Characters | 1335 |
| |
|  |
Section 28.9.
Printing with Field Widths and Precisions | 1335 |
| |
|  |
Section 28.10.
Using Flags in the printf Format String | 1337 |
| |
|  |
Section 28.11.
Printing with Argument Indices | 1342 |
| |
|  |
Section 28.12.
Printing Literals and Escape Sequences | 1342 |
| |
|  |
Section 28.13.
Formatting Output with Class Formatter | 1342 |
| |
|  |
Section 28.14.
Wrap-Up | 1344 |
| |
|  | Summary | 1344 |
| |
|  | Terminology | 1346 |
| |
|  | Self-Review Exercises | 1346 |
| |
|  | Answers to Self-Review Exercises | 1347 |
| |
|  | Exercises | 1348 |
| |  |
Chapter 29.
Strings, Characters and Regular Expressions | 1350 |
| |
|  |
Section 29.1.
Introduction | 1351 |
| |
|  |
Section 29.2.
Fundamentals of Characters and Strings | 1352 |
| |
|  |
Section 29.3.
Class String | 1352 |
| |
|  |
Section 29.4.
Class StringBuffer | 1364 |
| |
|  |
Section 29.5.
Class Character | 1372 |
| |
|  |
Section 29.6.
Class StringTokenizer | 1376 |
| |
|  |
Section 29.7.
Regular Expressions, Class Pattern and Class Matcher | 1378 |
| |
|  |
Section 29.8.
Wrap-Up | 1387 |
| |
|  | Summary | 1387 |
| |
|  | Terminology | 1391 |
| |
|  | Self-Review Exercises | 1391 |
| |
|  | Answers to Self-Review Exercises | 1392 |
| |
|  | Exercises | 1392 |
| |
|  | Special Section: Advanced String-Manipulation Exercises | 1393 |
| |
|  | Special Section: Challenging String-Manipulation Projects | 1396 |
| |  |
Appendix A.
Operator Precedence Chart | 1398 |
| |
|  |
Section A.1.
Operator Precedence | 1398 |
| |  |
Appendix B.
ASCII Character Set | 1400 |
| |  |
Appendix C.
Keywords and Reserved Words | 1401 |
| |  |
Appendix D.
Primitive Types | 1402 |
| |  |
Appendix E.
(On CD) Number Systems | 1403 |
| |  |
Appendix F.
(On CD) Unicode® | 1416 |
| |  |
Appendix G.
Using the Java API Documentation | 1427 |
| |
|  |
Section G.1.
Introduction | 1427 |
| |
|  |
Section G.2.
Navigating the Java API | 1428 |
| |  |
Appendix H.
(On CD) Creating Documentation with javadoc | 1437 |
| |  |
Appendix I.
(On CD) Bit Manipulation | 1449 |
| |  |
Appendix J.
(On CD) ATM Case Study Code | 1464 |
| |  |
Appendix K.
(On CD) Labeled break and continue Statements | 1489 |
| |  |
Appendix L.
(On CD) UML 2: Additional Diagram Types | 1492 |
| |  |
Appendix M.
(On CD) Design Patterns | 1494 |
| |  |
Appendix N.
Using the Debugger | 1515 |
| |  | End User License Agreements | EULA-1 |
| |
|  | Prentice Hall License Agreement and Limited Warranty | EULA-1 |
| |
|  | Apache Tomcat License Agreement | EULA-2 |
| |
|  | JCreator™ License Agreement | EULA-4 |
| |
|  | jEdit License Agreement | EULA-7 |
| |
|  | jGRASP™ License Agreement | EULA-11 |
| |
|  | NetBeans™ License Agreement | EULA-12 |
| |
|  | MySQL® Open Source License | EULA-17 |
| |  | Inside Back Cover | InsideBackCover |
| |
|  | License Agreement and Limited Warranty | InsideBackCover |
| |
|  | Using the CD-ROM | InsideBackCover |
| |
|  | Contents of the CD-ROM | InsideBackCover |
| |
|  | Software and Hardware System Requirements | InsideBackCover |
| |  | Index | |