Table of Contents
1.1 What is a programming language?
1.2 What is a program?
1.3 What is debugging?
1.4 Formal and natural languages
1.5 The first program
1.6 Glossary
1.7 Exercises
2.1 More printing
2.2 Variables
2.3 Assignment
2.4 Printing variables
2.5 Keywords
2.6 Operators
2.7 Order of operations
2.8 Operators for Strings
2.9 Composition
2.10 Glossary
2.11 Exercises
3.1 Floating-point
3.2 Converting from double to int
3.3 Math methods
3.4 Composition
3.5 Adding new methods
3.6 Classes and methods
3.7 Programs with multiple methods
3.8 Parameters and arguments
3.9 Stack diagrams
3.10 Methods with multiple parameters
3.11 Methods with results
3.12 Glossary
3.13 Exercises
4.1 The modulus operator
4.2 Conditional execution
4.3 Alternative execution
4.4 Chained conditionals
4.5 Nested conditionals
4.6 The return statement
4.7 Type conversion
4.8 Recursion
4.9 Stack diagrams for recursive methods
4.10 Convention and divine law
4.11 Glossary
4.12 Exercises
5.1 Return values
5.2 Program development
5.3 Composition
5.4 Overloading
5.5 Boolean expressions
5.6 Logical operators
5.7 Boolean methods
5.8 More recursion
5.9 Leap of faith
5.10 One more example
5.11 Glossary
5.12 Exercises
6.1 Multiple assignment
6.2 Iteration
6.3 The while statement
6.4 Tables
6.5 Two-dimensional tables
6.6 Encapsulation and generalization
6.7 Methods
6.8 More encapsulation
6.9 Local variables
6.10 More generalization
6.11 Glossary
6.12 Exercises
7.1 Invoking methods on objects
7.2 Length
7.3 Traversal
7.4 Run-time errors
7.5 Reading documentation
7.6 The indexOf method
7.7 Looping and counting
7.8 Increment and decrement operators
7.9 Strings are immutable
7.10 Strings are incomparable
7.11 Glossary
7.12 Exercises
8.1 What’s interesting?
8.2 Packages
8.3 Point objects
8.4 Instance variables
8.5 Objects as parameters
8.6 Rectangles
8.7 Objects as return types
8.8 Objects are mutable
8.9 Aliasing
8.10 null
8.11 Garbage collection
8.12 Objects and primitives
8.13 Glossary
8.14 Exercises
9.1 Class definitions and object types
9.2 Time
9.3 Constructors
9.4 More constructors
9.5 Creating a new object
9.6 Printing an object
9.7 Operations on objects
9.8 Pure functions
9.9 Modifiers
9.10 Fill-in methods
9.11 Which is best?
9.12 Incremental development vs. planning
9.13 Generalization
9.14 Algorithms
9.15 Glossary
9.16 Exercises
10.1 Accessing elements
10.2 Copying arrays
10.3 for loops
10.4 Arrays and objects
10.5 Array length
10.6 Random numbers
10.7 Array of random numbers
10.8 Counting
10.9 The histogram
10.10 A single-pass solution
10.11 Glossary
10.12 Exercises
11.1 Composition
11.2 Card objects
11.3 The printCard method
11.4 The sameCard method
11.5 The compareCard method
11.6 Arrays of cards
11.7 The printDeck method
11.8 Searching
11.9 Decks and subdecks
11.10 Glossary
11.11 Exercises
12.1 The Deck class
12.2 Shuffling
12.3 Sorting
12.4 Subdecks
12.5 Shuffling and dealing
12.6 Mergesort
12.7 Glossary
12.8 Exercises
13.1 Programming languages and styles
13.2 Object and class methods
13.3 The current object
13.4 Complex numbers
13.5 A function on Complex numbers
13.6 Another function on Complex numbers
13.7 A modifier
13.8 The toString method
13.9 The equals method
13.10 Invoking one object method from another
13.11 Oddities and errors
13.12 Inheritance
13.13 Drawable rectangles
13.14 The class hierarchy
13.15 Object-oriented design
13.16 Glossary
13.17 Exercises
14.1 References in objects
14.2 The Node class
14.3 Lists as collections
14.4 Lists and recursion
14.5 Infinite lists
14.6 The fundamental ambiguity theorem
14.7 Object methods for nodes
14.8 Modifying lists
14.9 Wrappers and helpers
14.10 The IntList class
14.11 Invariants
14.12 Glossary
14.13 Exercises
15.1 Abstract data types
15.2 The Stack ADT
15.3 The Java Stack Object
15.4 Wrapper classes
15.5 Creating wrapper objects
15.6 Creating more wrapper objects
15.7 Getting the values out
15.8 Useful methods in the wrapper classes
15.9 Postfix expressions
15.10 Parsing
15.11 Implementing ADTs
15.12 Array implementation of the Stack ADT
15.13 Resizing arrays
15.14 Glossary
15.15 Exercises
16.1 The queue ADT
16.2 Veneer
16.3 Linked Queue
16.4 Circular buffer
16.5 Priority queue
16.6 Metaclass
16.7 Array implementation of Priority Queue
16.8 A Priority Queue client
16.9 The Golfer class
16.10 Glossary
16.11 Exercises
17.1 A tree node
17.2 Building trees
17.3 Traversing trees
17.4 Expression trees
17.5 Traversal
17.6 Encapsulation
17.7 Defining a metaclass
17.8 Implementing a metaclass
17.9 The Vector class
17.10 The Iterator class
17.11 Glossary
17.12 Exercises
18.1 Array implementation of a tree
18.2 Performance analysis
18.3 Analysis of mergesort
18.4 Overhead
18.5 Priority Queue implementations
18.6 Definition of a Heap
18.7 Heap remove
18.8 Heap add
18.9 Performance of heaps
18.10 Heapsort
18.11 Glossary
18.12 Exercises
19.1 Arrays, Vectors and Maps
19.2 The Map ADT
19.3 The built-in HashMap
19.4 A Vector implementation
19.5 The List metaclass
19.6 HashMap implementation
19.7 Hash Functions
19.8 Resizing a hash map
19.9 Performance of resizing
19.10 Glossary
19.11 Exercises
20.1 Variable-length codes
20.2 The frequency table
20.3 The Huffman Tree
20.4 The super method
20.5 Decoding
20.6 Encoding
20.7 Glossary
B.1 Compile-time errors
B.2 Run-time errors
B.3 Semantic errors
D.1 Slates and Graphics objects
D.2 Invoking methods on a Graphics object
D.3 Coordinates
D.4 A lame Mickey Mouse
D.5 Other drawing commands
D.6 The Slate Class