Think Java
Allen B. Downey
Version 5.1.2
Preface
Contributors List
Contents
The way of the program
What is a programming language?
What is a program?
What is debugging?
Formal and natural languages
The first program
Glossary
Exercises
Variables and types
More printing
Variables
Assignment
Printing variables
Keywords
Operators
Order of operations
Operators for
Strings
Composition
Glossary
Exercises
Void methods
Floating-point
Converting from
double
to
int
Math methods
Composition
Adding new methods
Classes and methods
Programs with multiple methods
Parameters and arguments
Stack diagrams
Methods with multiple parameters
Methods that return values
Glossary
Exercises
Conditionals and recursion
The modulus operator
Conditional execution
Alternative execution
Chained conditionals
Nested conditionals
The return statement
Type conversion
Recursion
Stack diagrams for recursive methods
Glossary
Exercises
GridWorld: Part 1
Getting started
BugRunner
Exercises
Value methods
Return values
Program development
Composition
Overloading
Boolean expressions
Logical operators
Boolean methods
More recursion
Leap of faith
One more example
Glossary
Exercises
Iteration and loops
Multiple assignment
The
while
statement
Tables
Two-dimensional tables
Encapsulation and generalization
Methods and encapsulation
Local variables
More generalization
Glossary
Exercises
Strings and things
Characters
Length
Traversal
Run-time errors
Reading documentation
The
indexOf
method
Looping and counting
Increment and decrement operators
String
s are immutable
String
s are incomparable
Glossary
Exercises
Mutable objects
Packages
Point
objects
Instance variables
Objects as parameters
Rectangles
Objects as return types
Objects are mutable
Aliasing
null
Garbage collection
Objects and primitives
Glossary
Exercises
GridWorld: Part 2
Termites
Langton’s Termite
Exercises
Create your own objects
Class definitions and object types
Time
Constructors
More constructors
Creating a new object
Printing objects
Operations on objects
Pure functions
Modifiers
Fill-in methods
Incremental development and planning
Generalization
Algorithms
Glossary
Exercises
Arrays
Accessing elements
Copying arrays
Arrays and objects
for
loops
Array length
Random numbers
Array of random numbers
Counting
The histogram
A single-pass solution
Glossary
Exercises
Arrays of Objects
The Road Ahead
Card
objects
The
printCard
method
The
sameCard
method
The
compareCard
method
Arrays of cards
The
printDeck
method
Searching
Decks and subdecks
Glossary
Exercises
Objects of Arrays
The
Deck
class
Shuffling
Sorting
Subdecks
Shuffling and dealing
Mergesort
Class variables
Glossary
Exercises
Object-oriented programming
Programming languages and styles
Object methods and class methods
The
toString
method
The
equals
method
Oddities and errors
Inheritance
The class hierarchy
Object-oriented design
Glossary
Exercises
GridWorld: Part 3
ArrayList
Interfaces
public
and
private
Game of Life
LifeRunner
LifeRock
Simultaneous updates
Initial conditions
Exercises
Graphics
Java 2D Graphics
Graphics
methods
Coordinates
Color
Mickey Mouse
Glossary
Exercises
Input and Output in Java
System objects
Keyboard input
File input
Catching exceptions
Program development
Strategies
Failure modes
Debugging
Syntax errors
Run-time errors
Logic errors
Index
Like this book?
Are you using one of our books in a class?
We'd like to know about it. Please consider filling out
this short survey
.