810 Pages · 28.66 mb ·
Programming
- Cover (Page 1) - Contents (Page 6) - Preface (Page 16) - Chapter Coverage (Page 17) - Chapter Features (Page 20) - Goals (Page 20) - Timeline (Page 20) - Problem- Solving Case Studies (Page 20) - Testing and Debugging (Page 20) - Quick Checks (Page 20) - Exam Preparation Exercises (Page 20) - Programming Warm- Up Exercises (Page 20) - Programming Problems (Page 20) - Case Study Follow- Up Exercises (Page 21) - Supplements (Page 21) - Online Instructor’s ToolKit (Page 21) - Programs (Page 21) - Student Resource Disk for Java (Page 21) - Student Lecture Companion: A Note- Taking Guide ISBN : 076372372X (Page 21) - A Laboratory Course for Programming with Java™ ISBN : 0763724637 (Page 22) - Acknowledgements (Page 22) - 1 - Introduction to Object- Oriented Programming (Page 23) - Overview of Object- Oriented Programming (Page 25) - What Is Programming? (Page 25) - How Do We Write a Program? (Page 26) - How Is Java Code Converted into a Form That a Computer Can Use? (Page 31) - How Does Interpreting Code Differ from Executing It? (Page 35) - How Is Compilation Related to Interpretation and Execution? (Page 35) - What Kinds of Instructions Can Be Written in a Programming Language? (Page 36) - Object- Oriented Programming Languages (Page 39) - What’s Inside the Computer? (Page 41) - Problem- Solving Techniques (Page 43) - Ask Questions (Page 44) - Look for Things That Are Familiar (Page 45) - Solve by Analogy (Page 46) - Means- Ends Analysis (Page 46) - Divide and Conquer (Page 47) - The Building- Block Approach (Page 48) - Merging Solutions (Page 48) - Mental Blocks: The Fear of Starting (Page 49) - Object- Oriented Problem Solving (Page 50) - Testing and Debugging (Page 54) - 2 - Java Syntax and Semantics, Classes, and Objects (Page 61) - The Elements of Java Programs (Page 63) - Syntax and Semantics (Page 63) - Syntax Templates (Page 63) - Naming Program Elements: Identifiers (Page 67) - Built- in Types in Java (Page 68) - Classes and Objects (Page 71) - Defining Terms: Declarations (Page 75) - Field Declarations (Page 75) - Assignment and Expressions (Page 80) - Beyond Minimalism: Adding Comments to Code (Page 85) - Output (Page 85) - Input (Page 88) - Interactive Input and Output (Page 91) - Application Construction (Page 91) - Blocks (Page 94) - Application Entry, Correction, and Execution (Page 96) - Entering Application Code (Page 96) - Compiling and Running an Application (Page 98) - Finishing Up (Page 98) - Classes and Methods (Page 99) - User Classes (Page 99) - Methods (Page 100) - Testing and Debugging (Page 107) - 3 - Arithmetic Expressions (Page 119) - Overview of Java Data Types (Page 121) - Numeric Data Types (Page 124) - Integral Types (Page 124) - Floating- Point Types (Page 126) - Declarations for Numeric Types (Page 127) - Named Constant Declarations (Page 127) - Variable Declarations (Page 128) - Simple Arithmetic Expressions (Page 129) - Arithmetic Operators (Page 129) - Increment and Decrement Operators (Page 133) - Compound Arithmetic Expressions (Page 135) - Precedence Rules (Page 135) - Type Conversion and Type Casting (Page 136) - Additional Mathematical Methods (Page 141) - Value- Returning Class Methods (Page 143) - Additional String Operations (Page 147) - The length Method (Page 147) - The indexOf Method (Page 147) - The substring Method (Page 149) - Converting Strings to Numeric Values (Page 151) - Noninteractive Input/ Output (Page 152) - Applications with Multiple Class Files (Page 152) - Testing and Debugging (Page 161) - 4 - Selection and Encapsulation (Page 173) - Flow of Control (Page 175) - Selection (Page 175) - Conditions and Logical Expressions (Page 175) - The boolean Data Type (Page 176) - Logical Expressions (Page 176) - Precedence of Operators (Page 186) - Relational Operators with Floating- Point Types (Page 188) - The if Statement (Page 188) - The if- else Form (Page 189) - Blocks (Compound Statements) (Page 190) - The if Form (Page 191) - Nested if Statements (Page 194) - The Dangling else (Page 197) - Encapsulation (Page 198) - Abstraction (Page 200) - Data and Control Abstraction (Page 200) - Testing and Debugging (Page 211) - Testing Strategies (Page 211) - The Test Plan (Page 214) - Tests Performed Automatically During Compilation and Execution (Page 215) - 5 - File Objects and Looping Statements (Page 231) - File Input and Output (Page 233) - Files (Page 233) - Using Files (Page 234) - An Example Application Using Files (Page 240) - Looping (Page 241) - The while Statement (Page 242) - Phases of Loop Execution (Page 244) - Loops Using the while Statement (Page 244) - Count- Controlled Loops (Page 244) - Event- Controlled Loops (Page 246) - Looping Subtasks (Page 250) - How to Design Loops (Page 254) - Designing the Flow of Control (Page 254) - Designing the Process Within the Loop (Page 256) - The Loop Exit (Page 257) - Nested Loops (Page 257) - General Pattern (Page 258) - Designing Nested Loops (Page 261) - Mutable and Immutable Objects (Page 263) - A Parameter- Passing Analogy (Page 265) - Testing and Debugging (Page 273) - Loop- Testing Strategy (Page 273) - Test Plans Involving Loops (Page 273) - 6 - Object- Oriented Software Design and Implementation (Page 289) - Software Design Strategies (Page 291) - Objects and Classes Revisited (Page 292) - Object- Oriented Design (Page 295) - Object- Oriented Problem Solving (Page 296) - Software Engineering (Page 297) - The CRC Card Design Process (Page 298) - Identifying the Initial Classes Through Brainstorming (Page 298) - Filtering (Page 299) - Determining Responsibilities (Page 301) - Inheritance (Page 306) - Functional Decomposition (Page 306) - Writing Modules (Page 308) - Object- Oriented Implementation (Page 310) - Class Interface Design (Page 310) - Internal Data Representation (Page 312) - Responsibilities as Methods (Page 313) - Packages (Page 315) - Package Syntax (Page 315) - Packages with Multiple Compilation Units (Page 317) - Package Example (Page 318) - Ethics and Responsibilities in the Computing Profession (Page 322) - Software Piracy (Page 322) - Privacy of Data (Page 323) - Use of Computer Resources (Page 323) - Testing and Debugging (Page 335) - 7 - Inheritance, Polymorphism, and Scope (Page 345) - Inheritance (Page 347) - An Analogy (Page 347) - Inheritance and the Object- Oriented Design Process (Page 349) - How to Read a Class Hierarchy (Page 354) - Overriding (Page 357) - Hiding (Page 357) - Polymorphism (Page 358) - Derived Class Syntax (Page 358) - Scope of Access (Page 360) - Internal Scope (Page 361) - External Scope (Page 363) - Implementing a Derived Class (Page 367) - Constructors in Derived Classes (Page 368) - Overloading and Method Signatures (Page 368) - Accessing Overridden and Hidden Methods and Fields (Page 370) - A Concrete Example (Page 370) - Copy Constructors (Page 373) - Output and Input of Objects (Page 375) - Testing and Debugging (Page 386) - 8 - Event- Driven Input and Output (Page 395) - Frames (Page 397) - Import Classes and Declare Fields (Page 397) - Instantiate Frame Objects and Specify Some of Their Properties (Page 398) - Add Output to the Content Pane (Page 401) - Make the Frame Visible on the Screen (Page 401) - Formatting Output (Page 403) - Using GridLayout for Tabular Output (Page 403) - Alignment of Text Within JLabels (Page 405) - Event Handling (Page 406) - Creating a Button (Page 406) - Creating and Registering a Button Event Listener (Page 408) - An Event- Handling Example (Page 411) - Event Loops (Page 414) - Entering Data Using Fields in a Frame (Page 415) - Creating a Data Entry Field (Page 417) - Using a Field (Page 418) - Reading Data in an Event Handler (Page 419) - Handling Multiple Button Events (Page 430) - Testing and Debugging (Page 441) - 9 - Exceptions and Additional Control Structures (Page 451) - Exception- Handling Mechanism (Page 453) - The try- catch- finally Statement (Page 453) - Generating an Exception with throw (Page 456) - Exception Classes (Page 458) - Additional Control Statements (Page 459) - The switch Statement (Page 459) - The do Statement (Page 463) - The for Statement (Page 466) - Guidelines for Choosing a Looping Statement (Page 469) - Additional Java Operators (Page 469) - Assignment Operators and Assignment Expressions (Page 469) - Increment and Decrement Operators (Page 471) - Bitwise Operators (Page 472) - The ?: Operator (Page 477) - Operator Precedence (Page 477) - Testing and Debugging (Page 487) - 10 - One- Dimensional Arrays (Page 499) - Atomic Data Types (Page 501) - Composite Data Types (Page 502) - One- Dimensional Arrays (Page 504) - Declaring an Array (Page 507) - Creating an Array (Page 507) - Declaring and Creating an Array with an Initializer List (Page 509) - Accessing Individual Components (Page 509) - Out- of- Bounds Array Indexes (Page 511) - Aggregate Array Operations (Page 512) - Examples of Declaring and Processing Arrays (Page 514) - Occupancy Rates (Page 514) - Character Counts (Page 516) - Arrays of Objects (Page 518) - Arrays of Strings (Page 518) - Arrays of User- Defined Objects (Page 521) - Arrays and Methods (Page 521) - Special Kinds of Array Processing (Page 522) - Partial (or Sub) Array Processing (Page 522) - Indexes with Semantic Content (Page 522) - Testing and Debugging (Page 531) - 11 - Array- Based Lists (Page 543) - Lists (Page 545) - Brainstorming the List Class (Page 546) - CRC Card (Page 547) - Refining the Responsibilities (Page 547) - Internal Data Representation (Page 552) - Responsibility Algorithms for Class List (Page 552) - Test Plan (Page 557) - Sorting the List Items (Page 560) - Responsibility Algorithms for Class ListWithSort (Page 560) - Class ListWithSort (Page 562) - Sorted List (Page 564) - Brainstorming the Sorted List (Page 564) - Responsibility Algorithms for Class SortedList (Page 566) - Test Plan (Page 569) - The List Class Hierarchy and Abstract Classes (Page 569) - Searching (Page 571) - Sequential Search (Page 571) - Binary Search (Page 573) - Generic Lists (Page 580) - Polymorphism (Page 582) - Testing and Debugging (Page 592) - 12 - Multidimensional Arrays and Numeric Computation (Page 601) - Two- Dimensional Arrays (Page 603) - Array Declaration and Instantiation (Page 603) - Accessing Individual Components (Page 604) - Using Initializer Lists (Page 605) - Processing Two- Dimensional Arrays (Page 607) - Sum the Rows (Page 608) - Sum the Columns (Page 609) - Initialize the Array (Page 610) - Two- Dimensional Arrays and Methods (Page 611) - Multidimensional Arrays (Page 612) - Floating- Point Numbers (Page 613) - Representation of Floating- Point Numbers (Page 613) - Arithmetic with Floating- Point Numbers (Page 616) - Implementation of Floating- Point Numbers in the Computer (Page 617) - Decimal Format Type (Page 623) - Testing and Debugging (Page 640) - 13 - Recursion (Page 655) - What Is Recursion? (Page 657) - Power Function Definition (Page 657) - Power Function Implementation (Page 658) - More Examples with Simple Variables (Page 659) - Calculating the Factorial Function (Page 659) - Converting Decimal Integers to Binary Numbers (Page 662) - Towers of Hanoi (Page 665) - Recursive Algorithms with Structured Variables (Page 669) - Printing the Values in an Array (Page 669) - Binary Search (Page 672) - Recursion or Iteration? (Page 672) - Testing and Debugging (Page 673) - 14 - Applets (Page 679) - What Is an Applet? (Page 681) - How Do You Write an Applet? (Page 682) - Factorial (Page 682) - Calculator (Page 685) - How Do You Run an Applet? (Page 688) - Web Browsers (Page 688) - HTML (Page 689) - Factorial (Page 690) - Calculator (Page 691) - Testing and Debugging (Page 697) - Appendix A - Java Reserved Words (Page 703) - Appendix B - Operator Precedence (Page 704) - Appendix C - Primitive Data Types (Page 706) - Appendix D - ASCII Subset of Unicode (Page 707) - Appendix E - Decimal Format Type* (Page 708) - Appendix F - Program Style,Formatting,and Documentation (Page 713) - Glossary (Page 719) - Answers (Page 727) - Index (Page 765)