| |
| |
Preface | |
| |
| |
| |
Computers, Objects, and Java | |
| |
| |
| |
Welcome | |
| |
| |
| |
What Is a Computer? | |
| |
| |
| |
Networks, the Internet, and the World Wide Web | |
| |
| |
| |
Why Study Programming? | |
| |
| |
| |
Programming Languages | |
| |
| |
| |
Why Java? | |
| |
| |
| |
What Is Object-Oriented Programming? | |
| |
| |
Chapter Summary | |
| |
| |
Exercises | |
| |
| |
| |
Java Program Design and Development | |
| |
| |
| |
Introduction | |
| |
| |
| |
Designing Good Programs | |
| |
| |
| |
Designing a Riddle Program | |
| |
| |
| |
Java Language Elements | |
| |
| |
| |
Editing, Compiling, and Running a Java Program | |
| |
| |
| |
From the Java Library: System and PrintStream | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Objects: Using, Creating, and Defining | |
| |
| |
| |
Introduction | |
| |
| |
| |
Using String Objects | |
| |
| |
| |
Drawing Shapes with a Graphics Object (Optional) | |
| |
| |
| |
Class Definition | |
| |
| |
| |
CASE STUDY: Simulating a Two-Person Game | |
| |
| |
| |
From the Java Library: java.util.Scanner | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Methods: Communicating with Objects | |
| |
| |
| |
Introduction | |
| |
| |
| |
Passing Information to an Object | |
| |
| |
| |
Constructor Methods | |
| |
| |
| |
Retrieving Information from an Object | |
| |
| |
| |
Passing a Value and Passing a Reference | |
| |
| |
| |
Flow of Control: Control Structures | |
| |
| |
| |
Testing an Improved OneRowNim | |
| |
| |
| |
From the Java Library: java.lang.Object | |
| |
| |
| |
Object-Oriented Design: Inheritance and Polymorphism | |
| |
| |
| |
Drawing Lines and Defining Graphical Methods (Optional) | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Input/Output: Designing the User Interface | |
| |
| |
| |
Introduction | |
| |
| |
| |
The Use Interface | |
| |
| |
| |
A Command-Line Interface | |
| |
| |
| |
A Graphical User Interface (GUI) | |
| |
| |
| |
CASE STUDY: The One-Row Nim Game | |
| |
| |
| |
From the Java Library: java.io.File and File Input (Optional) | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Java Data and Operators | |
| |
| |
| |
Introduction | |
| |
| |
| |
Boolean Data and Operators | |
| |
| |
| |
Numeric Data and Operators | |
| |
| |
| |
From the Java Library: java.lang.Math | |
| |
| |
| |
Numeric Processing Examples | |
| |
| |
| |
From the Java Library: java.text.NumberFormat | |
| |
| |
| |
Character Data and Operators | |
| |
| |
| |
Example: Character Conversions | |
| |
| |
| |
Problem Solving = Representation + Action | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Control Structures | |
| |
| |
| |
Introduction | |
| |
| |
| |
Flow of Control: Repetition Structures | |
| |
| |
| |
Counting Loops | |
| |
| |
| |
Example: Car Loan | |
| |
| |
| |
Graphics Example: Drawing a Checkerboard | |
| |
| |
| |
Conditional Loops | |
| |
| |
| |
Example: Computing Averages | |
| |
| |
| |
Example: Data Validation | |
| |
| |
| |
Principles of Loop Design | |
| |
| |
| |
The switch Multiway Selection Structure | |
| |
| |
| |
Object-Oriented Design: Structured Programming | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Strings and String Processing | |
| |
| |
| |
Introduction | |
| |
| |
| |
String Basics | |
| |
| |
| |
Finding Things within a String | |
| |
| |
| |
Example: Keyword Search | |
| |
| |
| |
From the Java Library: java.lang.StringBuffer | |
| |
| |
| |
Retrieving Parts of Strings | |
| |
| |
| |
Example: Processing Names and Passwords | |
| |
| |
| |
Processing Each Character in a String | |
| |
| |
| |
Comparing Strings | |
| |
| |
| |
From the Java Library: java.util.StringTokenizer | |
| |
| |
| |
Handling Text in a Graphics Context (Optional) | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Inheritance and Polymorphism | |
| |
| |
| |
Introduction | |
| |
| |
| |
Java's Inheritance Mechanism | |
| |
| |
| |
Abstract Classes, Interfaces, and Polymorphism | |
| |
| |
| |
Example: A Toggle Button | |
| |
| |
| |
Example: The Cipher Class Hierarchy | |
| |
| |
| |
CASE STUDY: A Two-Player Game Hierarchy | |
| |
| |
| |
Principles of Object-Oriented Design | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Arrays and Array Processing | |
| |
| |
| |
Introduction | |
| |
| |
| |
One-Dimensional Arrays | |
| |
| |
| |
Simple Array Examples | |
| |
| |
| |
Example: Counting Frequencies of Letters | |
| |
| |
| |
Array Algorithms: Sorting | |
| |
| |
| |
Array Algorithms: Searching | |
| |
| |
| |
Two-Dimensional Arrays | |
| |
| |
| |
Multidimensional Arrays (Optional) | |
| |
| |
| |
Object-Oriented Design: Polymorphic Sorting (Optional) | |
| |
| |
| |
From the Java Library: java. lang. Vector | |
| |
| |
| |
CASE STUDY: An N-Player Computer Game | |
| |
| |
| |
A GUI-Based Game (Optional Graphics) | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Exceptions: When Things Go Wrong | |
| |
| |
| |
Introduction | |
| |
| |
| |
Handling Exceptional Conditions | |
| |
| |
| |
Java's Exception Hierarchy | |
| |
| |
| |
Handling Exceptions within a Program | |
| |
| |
| |
Error Handling and Robust Program Design | |
| |
| |
| |
Creating and Throwing Your Own Exceptions | |
| |
| |
| |
From the Java Library: javax.swing.JOptionPane | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Files and Streams: Input/Output Techniques | |
| |
| |
| |
Introduction | |
| |
| |
| |
Streams and Files | |
| |
| |
| |
CASE STUDY: Reading and Writing Text Files | |
| |
| |
| |
The File Class | |
| |
| |
| |
Example: Reading and Writing Binary Files | |
| |
| |
| |
Object Serialization: Reading and Writing Objects | |
| |
| |
| |
From the Java Library: javax.swing.JFileChooser | |
| |
| |
| |
Using File Data in Programs | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Recursive Problem Solving | |
| |
| |
| |
Introduction | |
| |
| |
| |
Recursive Definition | |
| |
| |
| |
Recursive String Methods | |
| |
| |
| |
Recursive Array Processing | |
| |
| |
| |
Example: Drawing (Recursive) Fractals | |
| |
| |
| |
Object-Oriented Design: Tail Recursion | |
| |
| |
| |
Object-Oriented Design: Recursion or Iteration? | |
| |
| |
| |
From the Java Library: javax.swing.JComboBox | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Graphical User Interfaces | |
| |
| |
| |
Introduction | |
| |
| |
| |
Java GUIs: From AWT to Swing | |
| |
| |
| |
The Swing Component Set | |
| |
| |
| |
Object-Oriented Design: Model-View-Controller Architecture | |
| |
| |
| |
The Java Event Model | |
| |
| |
| |
CASE STUDY: Designing a Basic GUI | |
| |
| |
| |
Containers and Layout Managers | |
| |
| |
| |
Checkboxes, Radio Buttons, and Borders | |
| |
| |
| |
Menus and Scroll Panes | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Threads and Concurrent Programming | |
| |
| |
| |
Introduction | |
| |
| |
| |
What Is a Thread? | |
| |
| |
| |
From the Java Library: java.lang.Thread | |
| |
| |
| |
Thread States and Life Cycle | |
| |
| |
| |
Using Threads to Improve Interface Responsiveness | |
| |
| |
| |
CASE STUDY: Cooperating Threads | |
| |
| |
| |
CASE STUDY: The Game of Pong | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Sockets and Networking | |
| |
| |
| |
Introduction | |
| |
| |
| |
An Overview of Networks | |
| |
| |
| |
Using Network Resources from an Applet | |
| |
| |
| |
From the Java Library: java.net.URL | |
| |
| |
| |
The Slide-Show Applet | |
| |
| |
| |
Using Network Resources from an Application | |
| |
| |
| |
Client/Server Communication via Sockets | |
| |
| |
| |
CASE STUDY: Generic Client/Server Classes | |
| |
| |
| |
Playing One-Row Nim Over the Network | |
| |
| |
| |
Java Network Security Restrictions | |
| |
| |
| |
Java Servlets and Java Server Pages | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Data Structures: Lists, Stacks, and Queues | |
| |
| |
| |
Introduction | |
| |
| |
| |
The Linked List Data Structure | |
| |
| |
| |
Object-Oriented Design: The List Abstract Data Type (ADT) | |
| |
| |
| |
The Stack ADT | |
| |
| |
| |
The Queue ADT | |
| |
| |
| |
From the Java Library: The Java Collections Framework and Generic Types | |
| |
| |
| |
Using the Set and Map Interfaces | |
| |
| |
| |
The Binary Search Tree Data Structure | |
| |
| |
Chapter Summary | |
| |
| |
Solutions to Self-Study Exercises | |
| |
| |
Exercises | |
| |
| |
| |
Coding Conventions | |
| |
| |
| |
The Java Development Kit | |
| |
| |
| |
The ASCII and Unicode Character Sets | |
| |
| |
| |
Java Keywords | |
| |
| |
| |
Operator Precedence Hierarchy | |
| |
| |
| |
Java Inner Classes | |
| |
| |
| |
Java Autoboxing and Enumeration | |
| |
| |
| |
Java and UML Resources | |
| |
| |
Index | |