Building Java Programs: A Back to Basics Approach
, 5th edition
by Stuart Reges and Marty Stepp
Authors' official companion web site
Main Page
Who's Using BJP?
Fifth Edition
Table of Contents
Supplements
Sample Chapters
Errata
Online Resources
Practice-It!
CodeStepByStep
Videos
MyProgrammingLab
Buy It!
How to Order
Get an Eval Copy
Fourth Edition (old)
Table of Contents
Sample Chapters
Supplements
Errata
Third Edition (old)
Table of Contents
Sample Chapters
Supplements
Errata
Table of Contents, 1st edition
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
Identifiers and Keywords
Comments and Readability
A Complex Example: DrawFigures1
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
print Versus println
Nested for Loops
2.4 Managing Complexity
Scope
Pseudocode
A Decrementing for Loop
Class Constants
2.5 Case Study: A Complex Figure
Problem Decomposition and Pseudocode
Line Pattern Table
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
Point Objects
Reference Semantics
Multiple Objects
Objects as Parameters to Methods
3.4 Interactive Programs
Scanner Objects
A Sample Interactive Program
3.5 Case Study: Projectile Trajectory
An Unstructured Solution
A Structured Solution
Supplement 3G: Graphics (optional)
3G.1 Introduction to Graphics
DrawingPanel
Lines and Shapes
Colors
Text and Fonts
3G.2 Procedural Decomposition with Graphics
A Larger Example: DrawDiamonds
Summary of Graphics Methods
3G.3 Case Study: Pyramids
An Unstructured Solution
Generalizing the Drawing of Pyramids
A Complete Structured Solution
Chapter 4: Conditional Execution
4.1 Loop Techniques
Cumulative Sum
Fencepost Loops (aka "loop and a half")
4.2 if/else Statements
Relational Operators
Cumulative Sum with if
Fencepost with if
Nested if/else
4.3 Subtleties of Conditional Execution
Object Equality
Roundoff Errors
Factoring if/else Statements
Min/Max Loops
4.4 Text Processing
The char Type
System.out.printf
4.5 Methods with Conditional Execution
Preconditions and Postconditions
Throwing Exceptions
Revisiting Return Values
4.6 Case Study: Body Mass Index (BMI)
One-person Unstructured Solution
Two-person Unstructured Solution
Two-person Structured Solution
Chapter 5: Program Logic and Indefinite Loops
5.1 The while Loop
A Loop to Find the Smallest Divisor
Sentinel Loops
Random Numbers
5.2 The boolean Type
Logical Operators
Short-Circuited Evaluation
boolean Variables and Flags
Boolean Zen
5.3 User Errors
Scanner Lookahead
Handling User Errors
5.4 Indefinite Loop Variations
The do/while Loop
Break and "forever" Loops
5.5 Assertions and Program Logic
Reasoning About Assertions
A Detailed Assertions Example
The Java assert Statement
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
Try/Catch Statements
6.5 Case Study: Weighted GPA
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
Limitations of Arrays
7.2 Array Traversal Algorithms
Printing an Array
Searching and Replacing
Testing for Equality
Reversing an Array
7.3 Advanced Array Techniques
Shifting Values in an Array
Arrays of Objects
Command Line Arguments
7.4 Multidimensional Arrays (optional)
Rectangular Two-Dimensional Arrays
Jagged Arrays
7.5 Case Study: Hours Worked
Version 1: Reading the Input File
Version 2: Cumulative Sum
Version 3: Row Sum and Column Print
Chapter 8: Classes
8.1 Object-Oriented Programming Concepts
Classes and Objects
8.2 Object State: Fields
8.3 Object Behavior: Methods
The Implicit Parameter
Mutators and Accessors
8.4 Object Initialization: Constructors
8.5 Encapsulation
Private Data Fields
Class Invariants
8.6 More Instance Methods
The toString Method
The equals Method
8.7 The this Keyword
Multiple Constructors
8.8 More Classes
Participant
TimeSpan
Changing Internal Implementations
8.9 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
Polymorphism
9.2 The Mechanics of Polymorphism
Diagramming Polymorphic Code
9.3 Interacting with the Superclass
Inherited Fields
Calling a Superclass's Constructor
Calling Overridden Methods
Another Example: MeteredPoint
The Object Class
9.4 Inheritance and Design
A Misuse of Inheritance: Point3D
Is-a versus Has-a
Graphics2D (optional)
9.5 Interfaces
An Interface for Shape Classes
Implementing the Shape Interface
Benefits of Interfaces
Interfaces in the Java Class Libraries
9.6 Case Study: Designing a Hierarchy of Financial Classes
Designing the Classes
Initial Redundant Implementation
Abstract Classes
Chapter 10: ArrayLists
10.1 ArrayLists
Basic ArrayList Operations
ArrayList Searching Methods
Sample ArrayList Problems
The for-each Loop
Wrapper Classes
10.2 The Comparable Interface
Natural Ordering and compareTo
Implementing Comparable
10.3 Case Study: Vocabulary Comparison
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
Mechanics of Recursion
12.3 Recursive Functions and Data
Integer Exponentiation
Greatest Common Divisor
Directory Crawler
12.4 Recursive Graphics (Optional)
12.5 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 Efficiency
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
The Complete Program
Chapter 14: Graphical User Interfaces
14.1 GUI Basics
Graphical Input and Output with Option Panes
Working with Frames
Buttons, Labels, and Text Fields
Changing a Frame's Layout
Handling an Action Event
14.2 Laying Out Components
Layout Managers
Composite Layout
14.3 Interaction Between Components
Object-Oriented GUIs
Another Example: Credit Card Validator
14.4 Additional Components and Events
Text Areas, Scrollbars, and Fonts
Icons
Mouse Events
14.5 2D Graphics
Drawing Onto Panels
Animation with Timers
14.6 Case Study: Implementing DrawingPanel
Initial Version Without Events
Second Version with Events
Appendix A: Answers to Self-Check Problems
Appendix B: Java Summary
Appendix C: Javadoc Comments and the Java API Specification
Index