| |
| |
Preface | |
| |
| |
| |
Introduction to Computers and Java | |
| |
| |
| |
Introduction | |
| |
| |
| |
Why Program? | |
| |
| |
| |
Computer Systems: Hardware and Software | |
| |
| |
| |
Programming Languages | |
| |
| |
| |
What Is a Program Made of? | |
| |
| |
| |
The Programming Process | |
| |
| |
| |
Object-Oriented Programming | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenge | |
| |
| |
| |
Java Fundamentals | |
| |
| |
| |
The Parts of a Java Program | |
| |
| |
| |
The print and println Methods, and the Java API | |
| |
| |
| |
Variables and Literals | |
| |
| |
| |
Primitive Data Types | |
| |
| |
| |
Arithmetic Operators | |
| |
| |
| |
Combined Assignment Operators | |
| |
| |
| |
Conversion between Primitive Data Types | |
| |
| |
| |
Creating Named Constants with final | |
| |
| |
| |
The String Class | |
| |
| |
| |
Scope | |
| |
| |
| |
Comments | |
| |
| |
| |
Programming Style | |
| |
| |
| |
Reading Keyboard Input | |
| |
| |
| |
Dialog Boxes | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Decision Structures | |
| |
| |
| |
The if Statement | |
| |
| |
| |
The if-else Statement | |
| |
| |
| |
The if-else-if Statement | |
| |
| |
| |
Nested if Statements | |
| |
| |
| |
Logical Operators | |
| |
| |
| |
Comparing String Objects | |
| |
| |
| |
More about Variable Declaration and Scope | |
| |
| |
| |
The Conditional Operator (Optional) | |
| |
| |
| |
The switch Statement | |
| |
| |
| |
Creating Objects with the Decimal Format Class | |
| |
| |
| |
The printf Method | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Loops and Files | |
| |
| |
| |
The Increment and Decrement Operators | |
| |
| |
| |
The while Loop | |
| |
| |
| |
Using the while Loop for Input Validation | |
| |
| |
| |
The do-while Loop | |
| |
| |
| |
The for Loop | |
| |
| |
| |
Running Totals and Sentinel Values | |
| |
| |
| |
Nested Loops | |
| |
| |
| |
The break and continue Statements (Optional) | |
| |
| |
| |
Deciding Which Loop to Use | |
| |
| |
| |
Introduction to File Input and Output | |
| |
| |
| |
The Random Class | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Methods | |
| |
| |
| |
Introduction to Methods | |
| |
| |
| |
Passing Arguments to a Method | |
| |
| |
| |
More about Local Variables | |
| |
| |
| |
Returning a Value from a Method | |
| |
| |
| |
Problem Solving with Methods | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
A First Look at Classes | |
| |
| |
| |
Classes and Objects | |
| |
| |
| |
Instance Fields and Methods | |
| |
| |
| |
Constructors | |
| |
| |
| |
Overloading Methods and Constructors | |
| |
| |
| |
Scope of Instance Fields | |
| |
| |
| |
Packages and import Statements | |
| |
| |
| |
Focus on Object-Oriented Design: Finding the Classes and Their Responsibilities | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
A First Look at GUI Applications | |
| |
| |
| |
Introduction | |
| |
| |
| |
Creating Windows | |
| |
| |
| |
Equipping GUI Classes with a main Method | |
| |
| |
| |
Layout Managers | |
| |
| |
| |
Radio Buttons and Check Boxes | |
| |
| |
| |
Borders | |
| |
| |
| |
Focus on Problem Solving: Extending Classes from JPanel | |
| |
| |
| |
Using Console Output to Debug a GUI Application | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Arrays and the ArrayList Class | |
| |
| |
| |
Introduction to Arrays | |
| |
| |
| |
Processing Array Elements | |
| |
| |
| |
Passing Arrays As Arguments to Methods | |
| |
| |
| |
Some Useful Array Algorithms and Operations | |
| |
| |
| |
Returning Arrays from Methods | |
| |
| |
| |
String Arrays | |
| |
| |
| |
Arrays of Objects | |
| |
| |
| |
The Sequential Search Algorithm | |
| |
| |
| |
Two-Dimensional Arrays | |
| |
| |
| |
Arrays with Three or More Dimensions | |
| |
| |
| |
Command-Line Arguments and Variable-Length Argument Lists | |
| |
| |
| |
The ArrayList Class | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
A Second Look at Classes and Objects | |
| |
| |
| |
Static Class Members | |
| |
| |
| |
Passing Objects As Arguments to Methods | |
| |
| |
| |
Returning Objects from Methods | |
| |
| |
| |
The toString Method | |
| |
| |
| |
Writing an equals Method | |
| |
| |
| |
Methods That Copy Objects | |
| |
| |
| |
Aggregation | |
| |
| |
| |
The this Reference Variable | |
| |
| |
| |
Enumerated Types | |
| |
| |
| |
Garbage Collection | |
| |
| |
| |
Focus on Object-Oriented Design: Class Collaboration | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Text Processing and More about Wrapper Classes | |
| |
| |
| |
Introduction to Wrapper Classes | |
| |
| |
| |
Character Testing and Conversion with the Character Class | |
| |
| |
| |
More String Methods | |
| |
| |
| |
The StringBuffer Class | |
| |
| |
| |
Tokenizing Strings | |
| |
| |
| |
Wrapper Classes for the Numeric Data Types | |
| |
| |
| |
Focus on Problem Solving: The TestScoreReader Class | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Inheritance | |
| |
| |
| |
What Is Inheritance? | |
| |
| |
| |
Calling the Superclass Constructor | |
| |
| |
| |
Overriding Superclass Methods | |
| |
| |
| |
Protected Members | |
| |
| |
| |
Chains of Inheritance | |
| |
| |
| |
The Object Class | |
| |
| |
| |
Polymorphism | |
| |
| |
| |
Abstract Classes and Abstract Methods | |
| |
| |
| |
Interfaces | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Exceptions and More about Stream I/O | |
| |
| |
| |
Handling Exceptions | |
| |
| |
| |
Throwing Exceptions | |
| |
| |
| |
More about Input/Output Streams | |
| |
| |
| |
Advanced Topics: Binary Files, Random Access Files, and Object Serialization | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Advanced GUI Applications | |
| |
| |
| |
The Swing and AWT Class Hierarchy | |
| |
| |
| |
Read-Only Text Fields | |
| |
| |
| |
Lists | |
| |
| |
| |
Combo Boxes | |
| |
| |
| |
Displaying Images in Labels and Buttons | |
| |
| |
| |
Mnemonics and Tool Tips | |
| |
| |
| |
File Choosers and Color Choosers | |
| |
| |
| |
Menus | |
| |
| |
| |
More about Text Components: Text Areas and Fonts | |
| |
| |
| |
Sliders | |
| |
| |
| |
Look and Feel | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Applets and More | |
| |
| |
| |
Introduction to Applets | |
| |
| |
| |
A Brief Introduction to HTML | |
| |
| |
| |
Creating Applets with Swing | |
| |
| |
| |
Using AWT for Portability | |
| |
| |
| |
Drawing Shapes | |
| |
| |
| |
Handling Mouse Events | |
| |
| |
| |
Timer Objects | |
| |
| |
| |
Playing Audio | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Recursion | |
| |
| |
| |
Introduction to Recursion | |
| |
| |
| |
Solving Problems with Recursion | |
| |
| |
| |
Examples of Recursive Methods | |
| |
| |
| |
The Towers of Hanoi | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Sorting, Searching, and Algorithm Analysis | |
| |
| |
| |
Introduction to Sorting Algorithms | |
| |
| |
| |
Introduction to Search Algorithms | |
| |
| |
| |
Analysis of Algorithms | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Generics | |
| |
| |
| |
Introduction to Generics | |
| |
| |
| |
Writing a Generic Class | |
| |
| |
| |
Passing Objects of a Generic Class to a Method | |
| |
| |
| |
Writing Generic Methods | |
| |
| |
| |
Constraining a Type Parameter in a Generic Class | |
| |
| |
| |
Inheritance and Generic Classes | |
| |
| |
| |
Defining Multiple Type Parameters | |
| |
| |
| |
Generics and Interfaces | |
| |
| |
| |
Erasure | |
| |
| |
| |
Restrictions on the Use of Generic Types | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Collections | |
| |
| |
| |
Introduction to the Java Collections Framework | |
| |
| |
| |
Lists | |
| |
| |
| |
Sets | |
| |
| |
| |
Maps | |
| |
| |
| |
The Collections Class | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Array-Based Lists | |
| |
| |
| |
Introduction to Lists | |
| |
| |
| |
Creating an Array-Based List to Hold String Objects | |
| |
| |
| |
Creating a Generic Array-Based List | |
| |
| |
| |
Writing Iterator Classes and Iterable Lists | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Linked Lists | |
| |
| |
| |
Introduction to Linked Lists | |
| |
| |
| |
Operations on Linked Lists | |
| |
| |
| |
Doubly-Linked and Circularly-Linked Lists | |
| |
| |
| |
Recursion on Linked Lists | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Stacks and Queues | |
| |
| |
| |
Stacks and Their Applications | |
| |
| |
| |
Array Implementation of Stacks | |
| |
| |
| |
Linked Implementation of Stacks | |
| |
| |
| |
Queues and Their Applications | |
| |
| |
| |
Array Implementation of Queues | |
| |
| |
| |
Linked List Implementation of Queues | |
| |
| |
| |
Generic Implementation of Stacks and Queues | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
| |
Binary Trees, AVL Trees, and Priority Queues | |
| |
| |
| |
Binary Trees and Their Applications | |
| |
| |
| |
Binary Search Trees | |
| |
| |
| |
AVL Trees | |
| |
| |
| |
Priority Queues | |
| |
| |
| |
Common Errors to Avoid | |
| |
| |
Review Questions and Exercises | |
| |
| |
Programming Challenges | |
| |
| |
Index | |
| |
| |
Student CD-ROM | |
| |
| |
| |
The ASCII/Unicode Characters | |
| |
| |
| |
Operator Precedence and Associativity | |
| |
| |
| |
Java Key Words | |
| |
| |
| |
Installing the JDK and JDK Documentation | |
| |
| |
| |
Using the javadoc Utility | |
| |
| |
| |
More about the Math Class | |
| |
| |
| |
Packages | |
| |
| |
| |
Working with Records and Random Access Files | |
| |
| |
| |
Using JBuilder 8 | |
| |
| |
| |
More about JOptionPane Dialog Boxes | |
| |
| |
| |
Answers to Checkpoints | |
| |
| |
| |
Answers to Odd-Numbered Review Questions | |
| |
| |
| |
Calculating Sales Commission | |
| |
| |
| |
The Amortization Class | |
| |
| |
| |
The PinTester Class | |
| |
| |
| |
Parallel Arrays | |
| |
| |
| |
The FeetInches Class | |
| |
| |
| |
The SerialNumber Class | |
| |
| |
| |
A Simple Text Editor Application | |