| |
| |
Preface | |
| |
| |
Java Fundamentals | |
| |
| |
The Origins of Java | |
| |
| |
How Java Relates to C and C++ | |
| |
| |
How Java Relates to C# | |
| |
| |
Java's Contribution to the Internet | |
| |
| |
Java Applets | |
| |
| |
Security | |
| |
| |
Portability | |
| |
| |
Java's Magic: The Bytecode | |
| |
| |
The Java Buzzwords | |
| |
| |
Object-Oriented Programming | |
| |
| |
Encapsulation | |
| |
| |
Polymorphism | |
| |
| |
Inheritance | |
| |
| |
Obtaining the Java Development Kit | |
| |
| |
A First Simple Program | |
| |
| |
Entering the Program | |
| |
| |
Compiling the Program | |
| |
| |
The First Sample Program Line by Line | |
| |
| |
Handling Syntax Errors | |
| |
| |
A Second Simple Program | |
| |
| |
Another Data Type | |
| |
| |
Converting Gallons to Liters | |
| |
| |
Two Control Statements | |
| |
| |
The if Statement | |
| |
| |
The for Loop | |
| |
| |
Create Blocks of Code | |
| |
| |
Semicolons and Positioning | |
| |
| |
Indentation Practices | |
| |
| |
Improving the Gallons-to-Liters Converter | |
| |
| |
The Java Keywords | |
| |
| |
Identifiers in Java | |
| |
| |
The Java Class Libraries | |
| |
| |
Mastery Check | |
| |
| |
Introducing Data Types and Operators | |
| |
| |
Why Data Types Are Important | |
| |
| |
Java's Primitive Types | |
| |
| |
Integers | |
| |
| |
Floating-Point Types | |
| |
| |
Characters | |
| |
| |
The Boolean Type | |
| |
| |
How Far Away Is the Lightning? | |
| |
| |
Literals | |
| |
| |
Hexadecimal and Octal Constants | |
| |
| |
Character Escape Sequences | |
| |
| |
String Literals | |
| |
| |
A Closer Look at Variables | |
| |
| |
Initializing a Variable | |
| |
| |
Dynamic Initialization | |
| |
| |
The Scope and Lifetime of Variables | |
| |
| |
Operators | |
| |
| |
Arithmetic Operators | |
| |
| |
Increment and Decrement | |
| |
| |
Relational and Logical Operators | |
| |
| |
Short-Circuit Logical Operators | |
| |
| |
The Assignment Operator | |
| |
| |
Shorthand Assignments | |
| |
| |
Type Conversion in Assignments | |
| |
| |
Casting Incompatible Types | |
| |
| |
Operator Precedence | |
| |
| |
Display a Truth Table for the Logical Operators | |
| |
| |
Expressions | |
| |
| |
Type Conversion in Expressions | |
| |
| |
Spacing and Parentheses | |
| |
| |
Mastery Check | |
| |
| |
Program Control Statements | |
| |
| |
Input Characters from the Keyboard | |
| |
| |
The if Statement | |
| |
| |
Nested ifs | |
| |
| |
The if-else-if Ladder | |
| |
| |
The switch Statement | |
| |
| |
Nested switch Statements | |
| |
| |
Start Building a Java Help System | |
| |
| |
The for Loop | |
| |
| |
Some Variations on the for Loop | |
| |
| |
Missing Pieces | |
| |
| |
Loops with No Body | |
| |
| |
Declaring Loop Control Variables Inside the for Loop | |
| |
| |
The Enhanced for Loop | |
| |
| |
The while Loop | |
| |
| |
The do-while Loop | |
| |
| |
Improve the Java Help System | |
| |
| |
Use break to Exit a Loop | |
| |
| |
Use break as a Form of goto | |
| |
| |
Use continue | |
| |
| |
Finish the Java Help System | |
| |
| |
Nested Loops | |
| |
| |
Mastery Check | |
| |
| |
Introducing Classes, Objects, and Methods | |
| |
| |
Class Fundamentals | |
| |
| |
The General Form of a Class | |
| |
| |
Defining a Class | |
| |
| |
How Objects Are Created | |
| |
| |
Reference Variables and Assignment | |
| |
| |
Methods | |
| |
| |
Adding a Method to the Vehicle Class | |
| |
| |
Returning from a Method | |
| |
| |
Returning a Value | |
| |
| |
Using Parameters | |
| |
| |
Adding a Parameterized Method to Vehicle | |
| |
| |
Creating a Help Class | |
| |
| |
Constructors | |
| |
| |
Parameterized Constructors | |
| |
| |
Adding a Constructor to the Vehicle Class | |
| |
| |
The new Operator Revisited | |
| |
| |
Garbage Collection and Finalizers | |
| |
| |
The finalize() Method | |
| |
| |
Demonstrate Finalization | |
| |
| |
The this Keyword | |
| |
| |
Mastery Check | |
| |
| |
More Data Types and Operators | |
| |
| |
Arrays | |
| |
| |
One-Dimensional Arrays | |
| |
| |
Sorting an Array | |
| |
| |
Multidimensional Arrays | |
| |
| |
Two-Dimensional Arrays | |
| |
| |
Irregular Arrays | |
| |
| |
Arrays of Three or More Dimensions | |
| |
| |
Initializing Multidimensional Arrays | |
| |
| |
Alternative Array Declaration Syntax | |
| |
| |
Assigning Array References | |
| |
| |
Using the length Member | |
| |
| |
A Queue Class | |
| |
| |
The For-Each Style for Loop | |
| |
| |
Iterating Over Multidimensional Arrays | |
| |
| |
Applying the Enhanced for | |
| |
| |
Strings | |
| |
| |
Constructing Strings | |
| |
| |
Operating on Strings | |
| |
| |
Arrays of Strings | |
| |
| |
Strings Are Immutable | |
| |
| |
Using Command-Line Arguments | |
| |
| |
The Bitwise Operators | |
| |
| |
The Bitwise AND, OR, XOR, and NOT Operators | |
| |
| |
The Shift Operators | |
| |
| |
Bitwise Shorthand Assignments | |
| |
| |
A ShowBits Class | |
| |
| |
The ? Operator | |
| |
| |
Mastery Check | |
| |
| |
A Closer Look at Methods and Classes | |
| |
| |
Controlling Access to Class Members | |
| |
| |
Java's Access Specifiers | |
| |
| |
Improving the Queue Class | |
| |
| |
Pass Objects to Methods | |
| |
| |
How Arguments Are Passed | |
| |
| |
Returning Objects | |
| |
| |
Method Overloading | |
| |
| |
Overloading Constructors | |
| |
| |
Overloading the Queue Constructor | |
| |
| |
Recursion | |
| |
| |
Understanding static | |
| |
| |
Static Blocks | |
| |
| |
The Quicksort | |
| |
| |
Introducing Nested and Inner Classes | |
| |
| |
Varargs: Variable-Length Arguments | |
| |
| |
Varargs Basics | |
| |
| |
Overloading Varargs Methods | |
| |
| |
Varargs and Ambiguity 247 | |
| |
| |
Mastery Check | |
| |
| |
Inheritance | |
| |
| |
Inheritance Basics | |
| |
| |
Member Access and Inheritance | |
| |
| |
Constructors and Inheritance | |
| |
| |
Using super to Call Superclass Constructors | |
| |
| |
Using super to Access Superclass Members | |
| |
| |
Extending the Vehicle Class | |
| |
| |
Creating a Multilevel Hierarchy | |
| |
| |
When Are Constructors Called? | |
| |
| |
Superclass References and Subclass Objects | |
| |
| |
Method Overriding | |
| |
| |
Overridden Methods Support Polymorphism | |
| |
| |
Why Overridden Methods? | |
| |
| |
Applying Method Overriding to TwoDShape | |
| |
| |
Using Abstract Classes | |
| |
| |
Using final | |
| |
| |
Final Prevents Overriding | |
| |
| |
Final Prevents Inheritance | |
| |
| |
Using final with Data Members | |
| |
| |
The Object Class | |
| |
| |
Mastery Check | |
| |
| |
Packages and Interfaces | |
| |
| |
Packages | |
| |
| |
Defining a Package | |
| |
| |
Finding Packages and Classpath | |
| |
| |
A Short Package Example | |
| |
| |
Packages and Member Access | |
| |
| |
A Package Access Example | |
| |
| |
Understanding Protected Members | |
| |
| |
Importing Packages | |
| |
| |
Java's Class Library Is Contained in Packages | |
| |
| |
Interfaces | |
| |
| |
Implementing Interfaces | |
| |
| |
Using Interface References | |
| |
| |
Creating a Queue Interface | |
| |
| |
Variables in Interfaces | |
| |
| |
Interfaces Can Be Extended | |
| |
| |
Mastery Check | |
| |
| |
Exception Handling | |
| |
| |
The Exception Hierarchy | |
| |
| |
Exception Handling Fundamentals | |
| |
| |
Using try and catch | |
| |
| |
A Simple Exception Example | |
| |
| |
The Consequences of an Uncaught Exception | |
| |
| |
Exceptions Enable You to Handle Errors Gracefully | |
| |
| |
Using Multiple catch Statements | |
| |
| |
Catching Subclass Exceptions | |
| |
| |
Try Blocks Can Be Nested | |
| |
| |
Throwing an Exception | |
| |
| |
Rethrowing an Exception | |
| |
| |
A Closer Look at Throwable | |
| |
| |
Using finally | |
| |
| |
Using throws | |
| |
| |
Java's Built-in Exceptions | |
| |
| |
Creating Exception Subclasses | |
| |
| |
Adding Exceptions to the Queue Class | |
| |
| |
Mastery Check | |
| |
| |
Using I/O | |
| |
| |
Java's I/O Is Built upon Streams | |
| |
| |
Byte Streams and Character Streams | |
| |
| |
The Byte Stream Classes | |
| |
| |
The Character Stream Classes | |
| |
| |
The Predefined Streams | |
| |
| |
Using the Byte Streams | |
| |
| |
Reading Console Input | |
| |
| |
Writing Console Output | |
| |
| |
Reading and Writing Files Using Byte Streams | |
| |
| |
Inputting from a File | |
| |
| |
Writing to a File | |
| |
| |
Reading and Writing Binary Data | |
| |
| |
A File Comparison Utility | |
| |
| |
Random Access Files | |
| |
| |
Using Java's Character-Based Streams | |
| |
| |
Console Input Using Character Streams | |
| |
| |
Console Output Using Character Streams | |
| |
| |
File I/O Using Character Streams | |
| |
| |
Using a FileWriter | |
| |
| |
Using a FileReader | |
| |
| |
Using Java's Type Wrappers to Convert Numeric Strings | |
| |
| |
Creating a Disk-Based Help System | |
| |
| |
Mastery Check | |
| |
| |
Multithreaded Programming | |
| |
| |
Multithreading Fundamentals | |
| |
| |
The Thread Class and Runnable Interface | |
| |
| |
Creating a Thread | |
| |
| |
Some Simple Improvements | |
| |
| |
Extending Thread | |
| |
| |
Creating Multiple Threads | |
| |
| |
Determining When a Thread Ends | |
| |
| |
Thread Priorities | |
| |
| |
Synchronization | |
| |
| |
Using Synchronized Methods | |
| |
| |
The synchronized Statement | |
| |
| |
Thread Communication Using notify(), wait(), and notifyAll() | |
| |
| |
An Example That Uses wait() and notify() | |
| |
| |
Suspending, Resuming, and Stopping Threads | |
| |
| |
Using the Main Thread | |
| |
| |
Mastery Check | |
| |
| |
Enumerations, Autoboxing, and Static Import | |
| |
| |
Enumerations | |
| |
| |
Enumeration Fundamentals | |
| |
| |
Java Enumerations Are Class Types | |
| |
| |
The values() and valueOf() Methods | |
| |
| |
Constructors, Methods, Instance Variables, and Enumerations | |
| |
| |
Two Important Restrictions | |
| |
| |
Enumerations Inherit Enum | |
| |
| |
A Computer-Controlled Traffic Light | |
| |
| |
Autoboxing | |
| |
| |
Type Wrappers | |
| |
| |
Autoboxing Fundamentals | |
| |
| |
Autoboxing and Methods | |
| |
| |
Autoboxing/Unboxing Occurs in Expressions | |
| |
| |
A Word of Warning | |
| |
| |
Static Import | |
| |
| |
Annotations (Metadata) | |
| |
| |
Mastery Check | |
| |
| |
Generics | |
| |
| |
Generics Fundamentals | |
| |
| |
A Simple Generics Example | |
| |
| |
Generics Work Only with Objects | |
| |
| |
Generic Types Differ Based on Their Type Arguments | |
| |
| |
A Generic Class with Two Type Parameters | |
| |
| |
The General Form of a Generic Class | |
| |
| |
Bounded Types | |
| |
| |
Using Wildcard Arguments | |
| |
| |
Bounded Wildcards | |
| |
| |
Generic Methods | |
| |
| |
Generic Constructors | |
| |
| |
Generic Interfaces | |
| |
| |
Create a Generic Queue | |
| |
| |
Raw Types and Legacy Code | |
| |
| |
Erasure | |
| |
| |
Ambiguity Errors | |
| |
| |
Some Generic Restrictions | |
| |
| |
Type Parameters Can't Be Instantiated | |
| |
| |
Restrictions on Static Members | |
| |
| |
Generic Array Restrictions | |
| |
| |
Generic Exception Restriction | |
| |
| |
Continuing Your Study of Generics | |
| |
| |
Mastery Check | |
| |
| |
Applets, Events, and Miscellaneous Topics | |
| |
| |
Applet Basics | |
| |
| |
Applet Organization and Essential Elements | |
| |
| |
The Applet Architecture | |
| |
| |
A Complete Applet Skeleton | |
| |
| |
Applet Initialization and Termination | |
| |
| |
Requesting Repainting | |
| |
| |
The update() Method | |
| |
| |
A Simple Banner Applet | |
| |
| |
Using the Status Window | |
| |
| |
Passing Parameters to Applets | |
| |
| |
The Applet Class | |
| |
| |
Event Handling | |
| |
| |
The Delegation Event Model | |
| |
| |
Events | |
| |
| |
Event Sources | |
| |
| |
Event Listeners | |
| |
| |
Event Classes | |
| |
| |
Event Listener Interfaces | |
| |
| |
Using the Delegation Event Model | |
| |
| |
Handling Mouse Events | |
| |
| |
A Simple Mouse Event Applet | |
| |
| |
More Java Keywords | |
| |
| |
The transient and volatile Modifiers | |
| |
| |
Instanceof | |
| |
| |
Strictfp | |
| |
| |
Assert | |
| |
| |
Native Methods | |
| |
| |
Mastery Check | |
| |
| |
Introducing Swing | |
| |
| |
The Origins and Design Philosophy of Swing | |
| |
| |
Components and Containers | |
| |
| |
Components | |
| |
| |
Containers | |
| |
| |
The Top-Level Container Panes | |
| |
| |
Layout Managers | |
| |
| |
A First Simple Swing Program | |
| |
| |
The First Swing Example Line by Line | |
| |
| |
Use JButton | |
| |
| |
Work with JTextField | |
| |
| |
Create a JCheckBox | |
| |
| |
Work with JList | |
| |
| |
A Swing-Based File Comparison Utility | |
| |
| |
Use Anonymous Inner Classes to Handle Events | |
| |
| |
Create a Swing Applet | |
| |
| |
What Next? | |
| |
| |
Mastery Check | |
| |
| |
Answers to Mastery Checks | |
| |
| |
Using Java's Documentation Comments | |
| |
| |
The javadoc Tags | |
| |
| |
@author | |
| |
| |
{@code} | |
| |
| |
@deprecated | |
| |
| |
{@docRoot} | |
| |
| |
@exception | |
| |
| |
{@inheritDoc} | |
| |
| |
{@link} | |
| |
| |
{@linkplain} | |
| |
| |
{@literal} | |
| |
| |
@param | |
| |
| |
@return | |
| |
| |
@see | |
| |
| |
@serial | |
| |
| |
@serialData | |
| |
| |
@serialField | |
| |
| |
@since | |
| |
| |
@throws | |
| |
| |
{@value} | |
| |
| |
@version | |
| |
| |
The General Form of a Documentation Comment | |
| |
| |
What javadoc Outputs | |
| |
| |
An Example that Uses Documentation Comments | |
| |
| |
Index | |