Preface
New Features in the Second Edition xiv
Major Features xv
Supplement Materials xxiv
Book Organization xxv
Acknowledgments xxvii
0 Introduction to Computers and Propamming Languages
O.1 A History of Computers 2
O.2 Computer Architecture 5
0.3 Programming Languages 11
0.4 Java 13
0.5 Exercises 14
1 Introduction to Object-Oriented Programming and Software Development
1.1 Classes and Objects 16
1.2 Messages and Methods 18
1.3 Class and Instance Data Values 23
1.4 Inheritance 26
1.5 Software Engineering and Software Life Cycle 29
1.6 Having Fun with Java 31
1.7 Exercises 34
2 Java Programming Basics
2.1 The First Java Application 38
2.2 Program Compojents 48
2.3 Edit-Compile-Run Cycle 59
2.4 The Javabook Package 61
2.5 Sample Program: Displaying Messages 62
2.6 The First Java Applet 66
2.7 Exercises 77
3 NUmerical Data
3.1 Variables 84
3.2 Arithmetic Expressions 92
3.3 Constants 98
3.4 The Math Clas 100
3.5 InputBox 103
3.6 OutputBox 106
3.7 Sample Program: Loan Calculator 113
3.8 Numerical Representation (Optional) 124
3.9 Exercises 128
4 Defining Instantiable Classes
4.1 Defining Instantiable Classes 140
4.2 Instantiable Classes and Constructors 152
4.3 Visbility Modifiers:public and Private 157
4.4 Local Variables,Return Values, and Parameter Passing 162
4.5 Loan Calculator Program with an Instantiable Class 167
4.6 Exercises 181
5 Processing Input with Applets
5.1 Placing GUI Objects on Applets 192
5.2 Adding ActionListener to an Event Source 199
5.3 Absolute Positioning of GUI Objects 206
5.4 The Button Class 208
5.5 Converting Text to a Numerical Value 210
5.6 Sample Program:Finding Body Mass Index (BMI)213
5.7 Running an Applet as an Application 223
5.8 Exercises 224
6 Selection Statements
6.1 The if Statement 230
6.2 Boolean Expressions and Variables238
6.3 Nested-of Statements 242
6.4 ListBox 249
6.5 The switch Statement 252
6.6 Sample Program:Drawing shapes 258
6.7 Exercises 280
7 Repetition Statements
7.1 The while Statement 290
7.2 Pitfalls in Writing Repetition Statements 294
7.3 The do-while Statement 299
7.4 ResponseBox 303
7.5 The for Statement 308
7.6 Nested -for Statements 312
7.7 The Format Class 316
7.8 Loan Tables 322
7.9 Sample Program:Hi-Lo Game 325
7.10 Recursive Methods (Optional)338
7.11 Exercises 343
8 Characters and Strings
8.1 Characters 356
8.2 Strings 359
8.3 Primitive versus Reference Types 370
8.4 StringBuffer 379
8.5 Passing Objects As Parameters 384
8.6 Returning an object from methods 389
8.7 Sample Program:Word Play 392
8.8 Exercises 404
9 Arrays
9.1 Array basics 412
9.2 Arrays of Objects 421
9.3 Passing Arrays to Methods 431
9.4 MultilnputBox 436
9.5 Self-Referencing Pointer 439
9.6 Sample development:The Address Book 446
9.7 Two-Dimensional Arrays 463
9.8 Vectors 470
9.9 Exercises 476
10 Sorting and Searching
10.1 Searching 4832
10.2 Sorting 488
10.3 Heapsort 495
10.4 Sample Program:Sorting an AddressBook 509
10.5 Exercises 515
11 File Input and Output
11.1 File and FileDialog Objects 520
11.2 Low-Level File I/O 525
11.3 High-Level File I/O 532
11.4 Handling Exceptions 539
11.5 Object I/O 544
11.6 Sample Class:Saving an AddressBook Object 548
11.7 Exercises 556
12 Reusable Classes and Packages
12.1 Object Categories 560
12.2 Method Overriding and Overloaded Methods 562
12.3 Sample Classes:Reusable EggyPeggy and HiLo 569+
12.4 Package Organization 595
12.5 Exercises 597
13 GUI Objects and Event-Driven Programming
13.1 Placing Buttons on a Frame 605
13.2 Handling Events 611
13.3 Placing TextField Objects on a frame 618
13.4 Menus 620
13.5 Handling Mouse Events 626
13.6 Other GUI Objects 634
13.7 Sample Program :A Simple Calculator 639
13.8 Exercises 652
14 Inheritance and polymorphism
14.1 Defining Classes with Inheritance 658
14.2 Using Classes Effectively with polymorphism 662
14.3 Inheritance and Member Accessibility 666
14.4 Inheritance and Constructors 672
14.5 Abstract Superclasses and Abstract Methods 676
14.6 When and When Not to Use Inheritance 682
14.7 Sample Program: Computing Course Grades 684
14.8 Exercises 704
15 Class Roster Maintenance Program
15.1 Method Call sequence Diagram 710
15.2 Problem Statement 711
15.3 Overall Planning 712
15.4 Step 1 Development:Program Shell with Mens 716
15.5 Step 2 Development: Create a Neww Roster 722
15.6 Step 3 Development: Add Students 729
15.7 Step 4 Development: Delete Students 737
15.8 Step 5 Development: Edit Student Names 740
15.9 Step 6 Development: Edit Test Scores and Compute Grades 746
15.10 Step 7 Development: Display Student Information 753
15.11 Step 8 Development: Storing Grade Rosters 765
15.12 Step 9 Development: finalize and Improve 775
15.13 The StudentNameDialog Class 786
15.14 The TestScoreDialog Class 786
15.15 Exercises 791
16 Recursive algorithms
16.1 Basic Elements of Recursion 798
16.2 Directory Listing 799
16.3 Anagram 801
16.4 Towers of Hanoi 805
16.5 Quicksort 809
16.6 When Not to Use Recursion 815
16.7 Exercises 817