PREFACE iii SPECIAL FEATURES xxii CHATER 1 INTRODUCTION 1 1.1 Computer Programs 2 1.2 The Anatomy of a Computer 3 1.3 The Java Programming Language 6 1.4 Becoming Familiar with Your Programming Environment 8 1.5 Analyzing Your First Program 12 1.6 Errors 15 1.7 Problem Solving: Algorithm Design 16 CHATER 2 USING OBJECTS 33 2.
1 Objects and Classes 34 2.2 Variables 36 2.3 Calling Methods 43 2.4 Constructing Objects 48 2.5 Accessor and Mutator Methods 50 2.6 The API Documentation 52 2.7 Implementing a Test Program 55 2.8 Object References 57 2.
9 Graphical Applications 61 2.10 Ellipses, Lines, Text, and Color 66 CHATER 3 IMPLEMENTING CLASSES 81 3.1 Instance Variables and Encapsulation 82 3.2 Specifying the Public Interface of a Class 86 3.3 Providing the Class Implementation 93 3.4 Unit Testing 102 3.5 Problem Solving: Tracing Objects 105 3.6 Local Variables 107 3.
7 The this reference 109 3.8 Shape Classes 112 CHATER 4 FUNDAMENTAL DATA TYPES 131 4.1 Numbers 132 4.2 Arithmetic 139 4.3 Input and Output 147 4.4 Problem Solving: First Do it By Hand 154 4.5 Strings 156 CHATER 5 DECISIONS 179 5.1 The if Statement 180 5.
2 Comparing Values 186 5.3 Multiple Alternatives 196 5.4 Nested Branches 200 5.5 Problem Solving: Flowcharts 207 5.6 Problem Solving: Selecting Test Cases 210 5.7 Boolean Variables and Operators 213 5.8 Application: Input Validation 218 CHAPTER 6 LOOPS 241 6.1 The While Loop 242 6.
2 Problem Solving: Hand-Tracing 249 6.3 The For Loop 254 6.4 The Do Loop 262 6.5 Application: Processing Sentinel Values 263 6.6 Problem Solving: Storyboards 269 6.7 Common Loop Algorithms 272 6.8 Nested Loops 279 6.9 Application: Random Numbers and Simulations 283 6.
10 Using a Debugger 286 CHAPTER 7 ARRAYS AND ARRAY LISTS 311 7.1 Arrays 312 7.2 The Enhanced For Loop 321 7.3 Common Array Algorithms 322 7.4 Problem Solving: Adapting Algorithms 331 7.5 Problem Solving: Discovering Algorithms By Manipulating Physical Objects 336 7.7 Array Lists 347 7.8 Regression Testing 356 CHATER 8 DESIGNING CLASSES 379 8.
1 Discovering Classes 380 8.2 Designing Good Methods 381 8.3 Problem Solving: Patterns for Object Data 390 8.4 Static Variables and Methods 395 8.5 Packages 400 8.6 Unit Test Frameworks 407 CHAPTER 9 INHERITANCE 421 9.1 Inheritance Hierarchies 422 9.2 Implementing Subclasses 426 9.
3 Overriding Methods 431 9.4 Polymorphism 437 9.5 Object: The cosmic Superclass 448 CHAPTER 10 INTERFACES 463 10.1 Using Interfaces for Algorithm Reuse 464 10.2 Working with Interface Variables 471 10.3 The Comparable Interface 473 10.4 Using Interfaces for Callbacks 477 10.5 Inner Classes 481 10.
6 Mock Objects 483 10.7 Event Handling 484 10.8 Building Applications with Buttons 490 10.9 Processing Timer Events 494 10.10 Mouse Events 497 CHAPTER 11 INPUT/OUTPUT AND EXCEPTION HANDLING 513 11.1 Reading and Writing Text files 514 11.2 Text Input and Output 519 11.3 Command Line arguments 527 11.
4 Exception Handling 534 11.5 Application: Handling Input errors 545 CHAPTER 12 OBJECT-ORIENTED DESIGN 559 12.1 Classes and Their Responsibilities 560 12.2 Relationships between Classes 563 12.3 Application: Printing an Invoice 569 CHAPTER 13 RECURSION 587 13.1 Triangle Numbers 588 13.2 Recursive Helper Methods 596 13.3 The Efficiency of Recursion 598 13.
4 Permutations 603 13.5 Mutual Recursion 608 13.6 Backtracking 614 14 SORTING AND SEARCHING 629 14.1 Selection Sort 630 14.2 Profiling the Selection Sort algorithm 633 14.3 analyzing the Performance of the Selection Sort algorithm 636 14.4 Merge Sort 641 14.5 analyzing the Merge Sort algorithm 644 14.
6 Searching 648 14.7 Problem Solving: estimating the running Time of an algorithm 653 14.8 Sorting and Searching in the Java Library 658 15 THE JAVA COLLECTIONS FRAMEWORK 671 15.1 an Overview of the collections framework 672 15.2 Linked Lists 675 15.3 Sets 681 15.4 Maps 686 15.5 Stacks, Queues, and Priority Queues 692 15.
6 Stack and Queue applications 695 16 BASIC DATA STRUCTURES 715 16.1 Implementing Linked Lists 716 16.2 Implementing array Lists 731 16.3 Implementing Stacks and Queues 735 16.4 Implementing a Hash Table 741 17 TREE STRUCTURES 761 17.1 Basic Tree concepts 762 17.2 Binary Trees 766 17.3 Binary Search Trees 771 17.
4 Tree Traversal 780 17.5 red-Black Trees 786 17.6 Heaps 793 17.7 The Heapsort algorithm 804 18 GENERIC CLASSES 819 18.1 Generic classes and Type Parameters 820 18.2 Implementing Generic Types 821 18.3 Generic Methods 825 18.4 constraining Type Parameters 827 18.
5 Type erasure 831 19 GRAPHICAL USER INTERFACES 841 19.1 Layout Management 842 19.2 Processing Text Input 846 19.3 choices 852 19.4 Menus 863 19.5 exploring the Swing Documentation 869 20 STREAMS AND BINARY INPUT/OUTPUT 881 20.1 readers, Writers, and Streams 882 20.2 Binary Input and Output 883 20.
3 random access 887 20.4 Object Streams 893 21 MULTITHREADING (WEB ONLY) 21.1 running Threads 21.2 Terminating Threads 21.3 race conditions 21.4 Synchronizing Object access 21.5 avoiding Deadlocks 21.6 application: algorithm animation 22 INTERNET NETWORKING (WEB ONLY) 22.
1 the Internet Protocol 22.2 Application Level Protocols 22.3 A Client Program 22.4 A Server Program 22.5 URL Connections 23 RELATIONAL DATABASES (WEB ONLY) 23.1 organizing database Information 23.2 Queries 23.3 Installing a database 23.
4 database Programming in Java 23.5 Application: entering an Invoice 24 XML (WEB ONLY) 24.1 XML tags and documents 24.2 Parsing XML documents 24.3 Creating XML documents 24.4 Validating XML documents 25 WEB APPLICATIONS (WEB ONLY) 25.1 The Architecture of a web Application 25.2 The Architecture of a JSF Application 25.
3 JavaBeans Components 25.4 Navigation Between Pages 25.5 JSF Components 25.6 A three-tier Application APPENDICES APPENDIX A THE BASIC LATIN AND LATIN-1 SUBSETS OF UNICODE A-1 APPENDIX B JAVA OPERATOR SUMMARY A-5 APPENDIX C JAVA RESERVED WORD SUMMARY A-7 APPENDIX D THE JAVA LIBRARY A-9 APPENDIX E JAVA SYNTAX SUMMARY A-53 APPENDIX F TOOL SUMMARY A-64 APPENDIX G NUMBER SYSTEMS A-68 APPENDIX H UML SUMMARY A-76 APPENDIX I JAVA LANGUAGE CODING GUIDELINES A-79 APPENDIX J HTML SUMMARY A-86 GLOSSARY G-1 INDEX I-1 CREDITS C-1 ALPHABETICAL LIST OF SYNTAX BOXES Arrays 313 Array Lists 347 Assignment 41 Calling a Superclass Method 431 Cast 143 Catching Exceptions 536 Class Declaration 89 Comparisons 187 Constant Declaration 136 Constructor with Superclass Initializer 436 Declaring a Generic Class 822 Declaring A Generic Method 826 Declaring an Interface 465 For Statement 254 If Statement 182 Implementing an Interface 467 Importing a Class from A Package 54 Input Statement 147 Instance Variable Declaration 83 Java Program 13 Object Construction 49 Package Specification 402 Subclass Declaration 428 The Enhanced For Loop 322 The Finally Clause 540 The Instance of Operator 451 The Throws Clause 539 Throwing an Exception 534 Two-Dimensional Array Declaration 341 While Statement 243 Variable Declaration 37.