Table of Contents, 3rd edition
Elements that have been newly added, moved, or substantially modified from the 2nd edition are highlighted for convenience.
Chapter 1: Introduction to Java Programming
- 1.1 Basic Computing Concepts
- Why Programming?
- Hardware and Software
- The Digital Realm
- Why Java?
- The Process of Programming
- The Java Programming Environment
- 1.2 And Now--Java
- String Literals (Strings)
- System.out.println
- Escape Sequences
- print versus println
- Identifiers and Keywords
- A Complex Example: DrawFigures1
- Comments and Readability
- 1.3 Program Errors
- Syntax Errors
- Logic Errors (bugs)
- 1.4 Procedural Decomposition
- Static Methods
- Flow of Control
- Methods That Call Other Methods
- An Example Runtime Error
- 1.5 Case Study: DrawFigures
- Structured Version
- Final Version without Redundancy
- Analysis of Flow of Execution
Chapter 2: Primitive Data and Definite Loops
- 2.1 Basic Data Concepts
- Primitive Types
- Expressions
- Literals
- Arithmetic Operators
- Precedence
- Mixing Types and Casting
- 2.2 Variables
- Assignment/Declaration Variations
- String Concatenation
- Increment/Decrement Operators
- Variables and Mixing Types
- 2.3 The for Loop
- Tracing for Loops
- for Loop Patterns
- Nested for Loops
- 2.4 Managing Complexity
- Scope
- Pseudocode
- Class Constants
- 2.5 Case Study: A Complex Figure
- Problem Decomposition and Pseudocode
- Initial Structured Version
- Adding a Class Constant
- Further Variations
Chapter 3: Introduction to Parameters and Objects
- 3.1 Parameters
- The Mechanics of Parameters
- Limitations of Parameters
- Multiple Parameters
- Parameters Versus Constants
- Overloading of Methods
- 3.2 Methods that Return Values
- The Math Class
- Defining Methods that Return Values
- 3.3 Using Objects
- String Objects
- Interactive Programs and Scanner Objects
- Sample Interactive Program
- 3.4 Case Study: Projectile Trajectory
- Unstructured Solution
- Structured Solution
Supplement 3G: Graphics
- 3G.1 Introduction to Graphics
- DrawingPanel
- Drawing Lines and Shapes
- Colors
- Drawing with Loops
- Text and Fonts
- 3G.2 Procedural Decomposition with Graphics
- A Larger Example: DrawDiamonds
- 3G.3 Case Study: Pyramids
- Unstructured Partial Solution
- Generalizing the Drawing of Pyramids
- Complete Structured Solution
Chapter 4: Conditional Execution
- 4.1 if/else Statements
- Relational Operators
- Nested if/else Statements
- Object Equality
- Factoring if/else Statements
- Multiple Conditions
- 4.2 Cumulative Algorithms
- Cumulative Sum
- Min/Max Loops
- Cumulative Sum with if
- Roundoff Errors
- 4.3 Text Processing
- The char Type
- char versus int
- Cumulative Text Algorithms
- System.out.printf
- 4.4 Methods with Conditional Execution
- Preconditions and Postconditions
- Throwing Exceptions
- Revisiting Return Values
- Reasoning about Paths
- 4.5 Case Study: Body Mass Index
- One-person Unstructured Solution
- Two-person Unstructured Solution
- Two-person Structured Solution
- Procedural Design Heuristics
Chapter 5: Program Logic and Indefinite Loops
- 5.1 The while Loop
- A Loop to Find the Smallest Divisor
- Random Numbers
- Simulations
- The do/while Loop
- 5.2 Fencepost Algorithms
- Sentinel Loops
- Fencepost with if
- 5.3 The boolean Type
- Logical Operators
- Short-Circuited Evaluation
- boolean Variables and Flags
- Boolean Zen
- Negating Boolean Expressions
- 5.4 User Errors
- Scanner Lookahead
- Handling User Errors
- 5.5 Assertions and Program Logic
- Reasoning About Assertions
- A Detailed Assertions Example
- 5.6 Case Study: NumberGuess
- Initial Version without Hinting
- Randomized Version with Hinting
- Final Robust Version
Chapter 6: File Processing
- 6.1 File Reading Basics
- Data, Data Everywhere
- File Basics
- Reading a File with a Scanner
- 6.2 Details of Token-Based Processing
- Structure of Files and Consuming Input
- Scanner Parameters
- Paths and Directories
- A More Complex Input File
- 6.3 Line-Based Processing
- String Scanners and Line/Token Combinations
- 6.4 Advanced File Processing
- Output Files with PrintStream
- Guaranteeing that Files Can Be Read
- 6.5 Case Study: ZIP Code Lookup
Chapter 7: Arrays
- 7.1 Array Basics
- Constructing and Traversing an Array
- Accessing an Array
- A Complete Array Program
- Random Access
- Arrays and Methods
- The For-Each Loop
- Initializing Arrays
- The Arrays Class
- 7.2 Array Traversal Algorithms
- Printing an Array
- Searching and Replacing
- Testing for Equality
- Reversing an Array
- String Traversal Algorithms
- 7.3 Reference Semantics
- 7.4 Advanced Array Techniques
- Shifting Values in an Array
- Arrays of Objects
- Command Line Arguments
- Nested Loop Algorithms
- 7.5 Multidimensional Arrays
- Rectangular Two-Dimensional Arrays
- Jagged Arrays
- 7.6 Case Study: Benford's Law
- Tallying values
- Completing the Program
Chapter 8: Classes
- 8.1 Object-Oriented Programming
- Classes and Objects
- Point Objects
- 8.2 Object State and Behavior
- Object State: Fields
- Object Behavior: Methods
- The Implicit Parameter
- Mutators and Accessors
- The toString Method
- 8.3 Object Initialization: Constructors
- The Keyword this
- Multiple Constructors
- 8.4 Encapsulation
- Private Data Fields
- Class Invariants
- Changing Internal Implementations
- 8.5 Case Study: Designing a Stock Class
- Object-Oriented Design Heuristics
- Stock Fields and Method Headers
- Stock Method and Constructor Implementation
Chapter 9: Inheritance and Interfaces
- 9.1 Inheritance Basics
- Non-programming Hierarchies
- Extending a Class
- Overriding Methods
- 9.2 Interacting with the Superclass
- Calling Overridden Methods
- Accessing Inherited Fields
- Calling a Superclass's Constructor
- DividendStock Behavior
- The Object Class
- The equals Method
- The instanceof Keyword
- 9.3 Polymorphism
- Polymorphism Mechanics
- Interpreting Inheritance Code
- Interpreting Complex Calls
- 9.4 Inheritance and Design
- A Misuse of Inheritance
- Is-a versus Has-a Relationships
- Graphics2D
- 9.5 Interfaces
- An Interface for Shapes
- Implementing an Interface
- Benefits of Interfaces
- 9.6 Case Study: Financial Class Hierarchy
- Designing the Classes
- Redundant Implementation
- Abstract Classes
Chapter 10: ArrayLists
- 10.1 ArrayLists
- Basic ArrayList Operations
- ArrayList Searching Methods
- A Complete ArrayList Program
- Adding to and Removing from an ArrayList
- Using the For-Each Loop with ArrayLists
- Wrapper Classes
- 10.2 The Comparable Interface
- Natural Ordering and compareTo
- Implementing the Comparable Interface
- 10.3 Case Study: Vocabulary Comparison
- Some Efficiency Considerations
- Version 1: Compute Vocabulary
- Version 2: Compute Overlap
- Version 3: Complete Program
Chapter 11: Java Collections Framework
- 11.1 Lists
- Collections
- LinkedList versus ArrayList
- Iterators
- Abstract Data Types (ADTs)
- LinkedList Case Study: Sieve
- 11.2 Sets
- Set Concepts
- TreeSet versus HashSet
- Set Operations
- Set Case Study: Lottery
- 11.3 Maps
- Basic Map Operations
- Map Views (keySet and values)
- TreeMap versus HashMap
- Map Case Study: WordCount
- Collection Overview
Chapter 12: Recursion
- 12.1 Thinking Recursively
- A Nonprogramming Example
- An Iterative Solution Converted to Recursion
- Structure of Recursive Solutions
- 12.2 A Better Example of Recursion
- 12.3 Recursive Functions and Data
- Integer Exponentiation
- Greatest Common Divisor
- Directory Crawler
- Helper Methods
- 12.4 Recursive Graphics
- 12.5 Recursive Backtracking
- A Simple Example: Traveling North/East
- 8 Queens Puzzle
- Solving Sudoku Puzzles
- 12.6 Case Study: Prefix Evaluator
- Infix, Prefix and Postfix Notation
- Evaluating Prefix Expressions
- Complete Program
Chapter 13: Searching and Sorting
- 13.1 Searching and Sorting in the Java Class Libraries
- Binary Search
- Sorting
- Shuffling
- Custom Ordering with Comparators
- 13.2 Program Complexity
- Empirical Analysis
- Complexity Classes
- 13.3 Implementing Searching and Sorting Algorithms
- Sequential Search
- Binary Search
- Recursive Binary Search
- Searching Objects
- Selection Sort
- 13.4 Case Study: Implementing Merge Sort
- Splitting and Merging Arrays
- Recursive Merge Sort
- Complete Program
Chapter 14: Stacks and Queues
- 14.1 Stack/Queue Basics
- Stack Concepts
- Queue Concepts
- 14.2 Common Stack/Queue Operations
- Transferring Between Stacks and Queues
- Sum of a Queue
- Sum of a Stack
- 14.3 Complex Stack/Queue Operations
- Removing Values from a Queue
- Comparing Two Stacks for Similarity
- 14.4 Case Study: Expression Evaluator
- Splitting into Tokens
- The Evaluator
Chapter 15: Implementing a Collection Class
- 15.1 Simple ArrayIntList
- Adding and Printing
- Thinking about Encapsulation
- Dealing with the Middle of the List
- Another Constructor and a Constant
- Preconditions and Postconditions
- 15.2 A More Complete ArrayIntList
- Throwing Exceptions
- Convenience Methods
- 15.3 Advanced Features
- Resizing When Necessary
- Adding an Iterator
- 15.4 ArrayList<E>
Chapter 16: Linked Lists
- 16.1 Working with Nodes
- Constructing a List
- List Basics
- Manipulating Nodes
- Traversing a List
- 16.2 A Linked List Class
- Simple LinkedIntList
- Appending add
- The Middle of the List
- 16.3 A Complex List Operation
- 16.4 An IntList Interface
- 16.5 LinkedList<E>
- Linked List Variations
- Linked List Iterators
- Other Code Details
Chapter 17: Binary Trees
- 17.1 Binary Tree Basics
- 17.2 Tree Traversals
- Constructing and Viewing a Tree
- 17.3 Common Tree Operations
- Sum of a Tree
- Counting Levels
- Counting Leaves
- 17.4 Binary Search Trees
- The Binary Search Tree Property
- Building a Binary Search Tree
- The Pattern x = change(x)
- Searching the Tree
- Binary Search Tree Complexity
- 17.5 SearchTree<E>
Chapter 18: Advanced Data Structures
- 18.1 Hashing
- Array Set Implementations
- Hash Functions and Hash Tables
- Collisions
- Rehashing
- Hashing Non-Integer Data
- Hash Map Implementation
- 18.2 Priority Queues and Heaps
- Priority Queues
- Introduction to Heaps
- Removing from a Heap
- Adding to a Heap
- Array Heap Implementation
- Heap Sort
Appendix A: Java Summary
- Java Keywords
- Primitive Types
- Operators
- Wrapper Classes
- Syntax Templates
- Useful Methods of ArrayList, Character, Collection, Collections, DrawingPanel, File, Graphics, Iterator, Map, Math, Object, Point, Random, Scanner, String
Appendix B: Javadoc Comments and the Java API Specification
- The Java API Specification
- Writing Javadoc Comments
Appendix C: Additional Java Syntax
- Primitive Types byte, short, long, float
- Ternary Operator ? :
- Exiting a Loop: break and continue
- The switch Statement
- The try/catch Statement
- The assert Statement
- Enumerations: enum
- Packages
- Protected and Default Access
Index