| | Copyright | |
| | Preface | xiii |
| | | What's New in the Third Edition? | xiii |
| | | Why Start with Objects? | xiv |
| | | Organization of the Text | xv |
| | Chapter 0. Computers, Objects, and Java | 1 |
| | | Section 0.1. Welcome | 2 |
| | | Section 0.2. What Is a Computer? | 2 |
| | | Section 0.3. Networks, the Internet, and the World Wide Web | 3 |
| | | Section 0.4. Why Study Programming? | 6 |
| | | Section 0.5. Programming Languages | 6 |
| | | Section 0.6. Why Java? | 8 |
| | | Section 0.7. What Is Object-Oriented Programming? | 10 |
| | | Chapter Summary | 18 |
| | | Exercises | 20 |
| | Chapter 1. Java Program Design and Development | 23 |
| | | Section 1.1. Introduction | 24 |
| | | Section 1.2. Designing Good Programs | 24 |
| | | Section 1.3. Designing a Riddle Program | 26 |
| | | Section 1.4. Java Language Elements | 33 |
| | | Section 1.5. Editing, Compiling, and Running a Java Program | 48 |
| | | Section 1.6. From the Java Library: System and PrintStream | 52 |
| | | Chapter Summary | 54 |
| | | Solutions to Self-Study Exercises | 56 |
| | | Exercises | 57 |
| | Chapter 2. Objects: Using, Creating, and Defining | 63 |
| | | Section 2.1. Introduction | 64 |
| | | Section 2.2. Using String Objects | 64 |
| | | Section 2.3. Drawing Shapes with a Graphics Object (Optional) | 68 |
| | | Section 2.4. Class Definition | 73 |
| | | Section 2.5. Case Study: Simulating a Two-Person Game | 78 |
| | | Section 2.6. From the Java Library: java.util.Scanner | 91 |
| | | Chapter Summary | 95 |
| | | Solutions to Self-Study Exercises | 96 |
| | | Exercises | 97 |
| | Chapter 3. Methods: Communicating with Objects | 103 |
| | | Section 3.1. Introduction | 104 |
| | | Section 3.2. Passing Information to an Object | 104 |
| | | Section 3.3. Constructor Methods | 111 |
| | | Section 3.4. Retrieving Information from an Object | 115 |
| | | Section 3.5. Passing a Value and Passing a Reference | 118 |
| | | Section 3.6. Flow of Control: Control Structures | 121 |
| | | Section 3.7. Testing an Improved OneRowNim | 129 |
| | | Section 3.8. From the Java Library: java.lang.Object | 133 |
| | | Section 3.9. Object-Oriented Design: Inheritance and Polymorphism | 135 |
| | | Section 3.10. Drawing Lines and Defining Graphical Methods (Optional) | 136 |
| | | Chapter Summary | 139 |
| | | Solutions to Self-Study Exercises | 140 |
| | | Exercises | 142 |
| | Chapter 4. Input/Output: Designing the User Interface | 149 |
| | | Section 4.1. Introduction | 150 |
| | | Section 4.2. The User Interface | 150 |
| | | Section 4.3. A Command-Line Interface | 151 |
| | | Section 4.4. A Graphical User Interface (GUI) | 159 |
| | | Section 4.5. Case Study: The One-Row Nim Game | 175 |
| | | Section 4.6. From the Java Library: java.io.File and File Input (Optional) | 183 |
| | | Chapter Summary | 186 |
| | | Solutions to Self-Study Exercises | 188 |
| | | Exercises | 190 |
| | Chapter 5. Java Data and Operators | 195 |
| | | Section 5.1. Introduction | 196 |
| | | Section 5.2. Boolean Data and Operators | 197 |
| | | Section 5.3. Numeric Data and Operators | 204 |
| | | Section 5.4. From the Java Library: java.lang.Math | 215 |
| | | Section 5.5. Numeric Processing Examples | 216 |
| | | Section 5.6. From the Java Library: java.text.NumberFormat | 228 |
| | | Section 5.7. Character Data and Operators | 230 |
| | | Section 5.8. Example: Character Conversions | 233 |
| | | Section 5.9. Problem Solving = Representation + Action | 236 |
| | | Chapter Summary | 236 |
| | | Solutions to Self-Study Exercises | 238 |
| | | Exercises | 242 |
| | Chapter 6. Control Structures | 249 |
| | | Section 6.1. Introduction | 250 |
| | | Section 6.2. Flow of Control: Repetition Structures | 250 |
| | | Section 6.3. Counting Loops | 251 |
| | | Section 6.4. Example: Car Loan | 260 |
| | | Section 6.5. Graphics Example: Drawing a Checkerboard | 262 |
| | | Section 6.6. Conditional Loops | 266 |
| | | Section 6.7. Example: Computing Averages | 272 |
| | | Section 6.8. Example: Data Validation | 275 |
| | | Section 6.9. Principles of Loop Design | 277 |
| | | Section 6.10. The switch Multiway Selection Structure | 278 |
| | | Section 6.11. Object-Oriented Design: Structured Programming | 282 |
| | | Chapter Summary | 290 |
| | | Solutions to Self-Study Exercises | 291 |
| | | Exercises | 298 |
| | Chapter 7. Strings and String Processing | 305 |
| | | Section 7.1. Introduction | 306 |
| | | Section 7.2. String Basics | 306 |
| | | Section 7.3. Finding Things within a String | 313 |
| | | Section 7.4. Example: Keyword Search | 315 |
| | | Section 7.5. From the Java Library: java.lang.StringBuffer | 317 |
| | | Section 7.6. Retrieving Parts of Strings | 320 |
| | | Section 7.7. Example: Processing Names and Passwords | 322 |
| | | Section 7.8. Processing Each Character in a String | 323 |
| | | Section 7.9. Comparing Strings | 326 |
| | | Section 7.10. From the Java Library: java.util.StringTokenizer | 332 |
| | | Section 7.11. Handling Text in a Graphics Context (Optional) | 334 |
| | | Chapter Summary | 340 |
| | | Solutions to Self-Study Exercises | 341 |
| | | Exercises | 344 |
| | Chapter 8. Inheritance and Polymorphism | 349 |
| | | Section 8.1. Introduction | 350 |
| | | Section 8.2. Java's Inheritance Mechanism | 350 |
| | | Section 8.3. Abstract Classes, Interfaces, and Polymorphism | 359 |
| | | Section 8.4. Example: A Toggle Button | 365 |
| | | Section 8.5. Example: The Cipher Class Hierarchy | 368 |
| | | Section 8.6. Case Study: A Two-Player Game Hierarchy | 375 |
| | | Section 8.7. Principles of Object-Oriented Design | 396 |
| | | Chapter Summary | 397 |
| | | Solutions to Self-Study Exercises | 398 |
| | | Exercises | 400 |
| | Chapter 9. Arrays and Array Processing | 405 |
| | | Section 9.1. Introduction | 406 |
| | | Section 9.2. One-Dimensional Arrays | 406 |
| | | Section 9.3. Simple Array Examples | 413 |
| | | Section 9.4. Example: Counting Frequencies of Letters | 416 |
| | | Section 9.5. Array Algorithms: Sorting | 420 |
| | | Section 9.6. Array Algorithms: Searching | 426 |
| | | Section 9.7. Two-Dimensional Arrays | 430 |
| | | Section 9.8. Multidimensional Arrays (Optional) | 437 |
| | | Section 9.9. Object-Oriented Design: Polymorphic Sorting (Optional) | 439 |
| | | Section 9.10. From the Java Library: java.lang.Vector | 443 |
| | | Section 9.11. CASE STUDY: An N-Player Computer Game | 444 |
| | | Section 9.12. A GUI-Based Game (Optional Graphics) | 452 |
| | | Chapter Summary | 459 |
| | | Solutions to Self-Study Exercises | 460 |
| | | Exercises | 465 |
| | Chapter 10. Exceptions: When Things Go Wrong | 471 |
| | | Section 10.1. Introduction | 472 |
| | | Section 10.2. Handling Exceptional Conditions | 472 |
| | | Section 10.3. Java's Exception Hierarchy | 474 |
| | | Section 10.4. Handling Exceptions within a Program | 478 |
| | | Section 10.5. Error Handling and Robust Program Design | 488 |
| | | Section 10.6. Creating and Throwing Your Own Exceptions | 497 |
| | | Section 10.7. From the Java Library: javax.swing.JOptionPane | 501 |
| | | Chapter Summary | 503 |
| | | Solutions to Self-Study Exercises | 505 |
| | | Exercises | 507 |
| | Chapter 11. Files and Streams: Input/Output Techniques | 511 |
| | | Section 11.1. Introduction | 512 |
| | | Section 11.2. Streams and Files | 512 |
| | | Section 11.3. Case Study: Reading and Writing Text Files | 518 |
| | | Section 11.4. The File Class | 530 |
| | | Section 11.5. Example: Reading and Writing Binary Files | 533 |
| | | Section 11.6. Object Serialization: Reading and Writing Objects | 542 |
| | | Section 11.7. From the Java Library: javax.swing.JFileChooser | 547 |
| | | Section 11.8. Using File Data in Programs | 548 |
| | | Chapter Summary | 551 |
| | | Solutions to Self-Study Exercises | 552 |
| | | Exercises | 553 |
| | Chapter 12. Recursive Problem Solving | 557 |
| | | Section 12.1. Introduction | 558 |
| | | Section 12.2. Recursive Definition | 561 |
| | | Section 12.3. Recursive String Methods | 564 |
| | | Section 12.4. Recursive Array Processing | 574 |
| | | Section 12.5. Example: Drawing (Recursive) Fractals | 580 |
| | | Section 12.6. Object-Oriented Design: Tail Recursion | 584 |
| | | Section 12.7. Object-Oriented Design: Recursion or Iteration? | 586 |
| | | Section 12.8. From the Java Library: javax.swing.JComboBox | 588 |
| | | Chapter Summary | 594 |
| | | Solutions to Self-Study Exercises | 595 |
| | | Exercises | 599 |
| | Chapter 13. Graphical User Interfaces | 603 |
| | | Section 13.1. Introduction | 604 |
| | | Section 13.2. Java GUIs: From AWT to Swing | 604 |
| | | Section 13.3. The Swing Component Set | 607 |
| | | Section 13.4. Object-Oriented Design: Model-View-Controller Architecture | 607 |
| | | Section 13.5. The Java Event Model | 609 |
| | | Section 13.6. Case Study: Designing a Basic GUI | 614 |
| | | Section 13.7. Containers and Layout Managers | 627 |
| | | Section 13.8. Checkboxes, Radio Buttons, and Borders | 633 |
| | | Section 13.9. Menus and Scroll Panes | 641 |
| | | Chapter Summary | 650 |
| | | Solutions to Self-Study Exercises | 651 |
| | | Exercises | 653 |
| | Chapter 14. Threads and Concurrent Programming | 657 |
| | | Section 14.1. Introduction | 658 |
| | | Section 14.2. What Is a Thread? | 658 |
| | | Section 14.3. From the Java Library: java.lang.Thread | 662 |
| | | Section 14.4. Thread States and Life Cycle | 668 |
| | | Section 14.5. Using Threads to Improve Interface Responsiveness | 670 |
| | | Section 14.6. Case Study: Cooperating Threads | 678 |
| | | Section 14.7. Case Study: The Game of Pong | 693 |
| | | Chapter Summary | 700 |
| | | Solutions to Self-Study Exercises | 702 |
| | | Exercises | 704 |
| | Chapter 15. Sockets and Networking | 707 |
| | | Section 15.1. Introduction | 708 |
| | | Section 15.2. An Overview of Networks | 708 |
| | | Section 15.3. Using Network Resources from an Applet | 714 |
| | | Section 15.4. From the Java Library: java.net.URL | 715 |
| | | Section 15.5. The Slide-Show Applet | 717 |
| | | Section 15.6. Using Network Resources from an Application | 722 |
| | | Section 15.7. Client/Server Communication via Sockets | 732 |
| | | Section 15.8. CASE STUDY: Generic Client/Server Classes | 736 |
| | | Section 15.9. Playing One-Row Nim Over the Network | 745 |
| | | Section 15.10. Java Network Security Restrictions | 752 |
| | | Section 15.11. Java Servlets and Java Server Pages | 753 |
| | | Chapter Summary | 762 |
| | | Solutions to Self-Study Exercises | 763 |
| | | Exercises | 765 |
| | Chapter 16. Data Structures: Lists, Stacks, and Queues | 767 |
| | | Section 16.1. Introduction | 768 |
| | | Section 16.2. The Linked List Data Structure | 768 |
| | | Section 16.3. Object-Oriented Design: The List Abstract Data Type (ADT) | 780 |
| | | Section 16.4. The Stack ADT | 785 |
| | | Section 16.5. The Queue ADT | 788 |
| | | Section 16.6. From the Java Library: The Java Collections Framework and Generic Types | 791 |
| | | Section 16.7. Using the Set and Map Interfaces | 795 |
| | | Section 16.8. The Binary Search Tree Data Structure | 799 |
| | | Chapter Summary | 801 |
| | | Solutions to Self-Study Exercises | 803 |
| | | Exercises | 806 |
| | Appendix A. Coding Conventions | 811 |
| | | Comments | 811 |
| | | Indentation and White Space | 813 |
| | | Naming Conventions | 813 |
| | | Use of Braces | 814 |
| | | File Names and Layout | 815 |
| | | Statements | 816 |
| | | Executable Statements | 817 |
| | | Preconditions and Postconditions | 818 |
| | | Sample Programs | 818 |
| | Appendix B. The Java Development Kit | 819 |
| | | The Java Compiler: javac | 819 |
| | | The Java Interpreter: java | 821 |
| | | The appletviewer | 821 |
| | | The Java Archiver jar Tool | 825 |
| | | The Java Documentation Tool: javadoc | 827 |
| | Appendix C. The ASCII and Unicode Character Sets | 828 |
| | Appendix D. Java Keywords | 829 |
| | Appendix E. Operator Precedence Hierarchy | 830 |
| | Appendix F. Java Inner Classes | 832 |
| | | What Are Inner Classes? | 832 |
| | | Nested Top-Level Versus Member Classes | 832 |
| | | Local and Anonymous Inner Classes | 834 |
| | Appendix G. Java Autoboxing and Enumeration | 837 |
| | | Autoboxing and Unboxing | 837 |
| | | Enumeration | 838 |
| | Appendix H. Java and UML Resources | 841 |
| | | Reference Books | 841 |
| | | Online References | 841 |
| | Index | |