1 The History and Evolution of Java
Java’s Lineage
The Birth of Modern Programming: C
C++: The Next Step
The Stage Is Set for Java
The Creation of Java
The C# Connection
How Java Changed the Internet
Java Applets
Security Important - Must Read
Portability Important - Must Read
Java’s Magic: The Bytecode Important - Must Read
Servlets: Java on the Server Side
The Java Buzzwords Important - Must Read
Simple Important - Must Read
Object-Oriented Important - Must Read
Robust Important - Must Read
Multithreaded Important - Must Read
Architecture-Neutral Important - Must Read
Interpreted and High Performance
The Evolution of Java
Java SE 6
A Culture of Innovation
2 An Overview of Java
Object-Oriented Programming
Two Paradigms
Abstraction Important - Must Read
The Three OOP Principles Important - Must Read
A First Simple Program
Entering the Program
Compiling the Program
A Closer Look at the First Sample Program
A Second Short Program
Two Control Statements
The if Statement
The for Loop
Using Blocks of Code Important - Must Read
Lexical Issues
The Java Keywords
The Java Class Libraries
3 Data Types, Variables, and Arrays
Java Is a Strongly Typed Language
The Primitive Types
Floating-Point Types
A Closer Look at Literals Important - Must Read
Integer Literals
Floating-Point Literals
Boolean Literals
Character Literals
String Literals
Declaring a Variable
Dynamic Initialization
The Scope and Lifetime of Variables Important - Must Read
Type Conversion and Casting Important - Must Read
Java’s Automatic Conversions Important - Must Read
Casting Incompatible Types
Automatic Type Promotion in Expressions
The Type Promotion Rules
Arrays Important - Must Read
One-Dimensional Arrays Important - Must Read
Multidimensional Arrays Important - Must Read
Alternative Array Declaration Syntax Important - Must Read
A Few Words About Strings
A Note to C/C++ Programmers About Pointers
4 Operators
Arithmetic Operators
The Basic Arithmetic Operators
The Modulus Operator
Arithmetic Compound Assignment Operators
Increment and Decrement
The Bitwise Operators
The Bitwise Logical Operators
The Left Shift Important - Must Read
The Right Shift Important - Must Read
The Unsigned Right Shift
Bitwise Operator Compound Assignments
Relational Operators
Boolean Logical Operators
Short-Circuit Logical Operators
The Assignment Operator
The ? Operator Important - Must Read
Operator Precedence
Using Parentheses
5 Control Statements
Java’s Selection Statements
Iteration Statements
The For-Each Version of the for Loop Important - Must Read
Nested Loops
Jump Statements
Using break
Using continue
6 Introducing Classes
Class Fundamentals
The General Form of a Class
A Simple Class
Declaring Objects
A Closer Look at new
Assigning Object Reference Variables
Introducing Methods
Adding a Method to the Box Class
Returning a Value
Adding a Method That Takes Parameters
Constructors Important - Must Read
Parameterized Constructors Important - Must Read
The this Keyword Important - Must Read
Instance Variable Hiding Important - Must Read
Garbage Collection Important - Must Read
The finalize( ) Method Important - Must Read
A Stack Class
7 A Closer Look at Methods and Classes
Overloading Methods Important - Must Read
Overloading Constructors Important - Must Read
Using Objects as Parameters Important - Must Read
A Closer Look at Argument Passing Important - Must Read
Returning Objects Important - Must Read
Recursion Important - Must Read
Introducing Access Control Important - Must Read
Understanding static Important - Must Read
Introducing final Important - Must Read
Arrays Revisited
Introducing Nested and Inner Classes Important - Must Read
Exploring the String Class
Using Command-Line Arguments Important - Must Read
Varargs: Variable-Length Arguments Important - Must Read
Overloading Vararg Methods Important - Must Read
Varargs and Ambiguity Important - Must Read
8 Inheritance
Inheritance Basics
Member Access and Inheritance
A More Practical Example
A Superclass Variable Can Reference a Subclass Object Important - Must Read
Using super Important - Must Read
Using super to Call Superclass Constructors Important - Must Read
A Second Use for super
Creating a Multilevel Hierarchy Important - Must Read
When Constructors Are Called
Method Overriding Important - Must Read
Dynamic Method Dispatch Important - Must Read
Why Overridden Methods? Important - Must Read
Applying Method Overriding Important - Must Read
Using Abstract Classes Important - Must Read
Using final with Inheritance Important - Must Read
Using final to Prevent Overriding Important - Must Read
Using final to Prevent Inheritance Important - Must Read
The Object Class
9 Packages and Interfaces
Packages Important - Must Read
Defining a Package Important - Must Read
Finding Packages and CLASSPATH
A Short Package Example
Access Protection
An Access Example Important - Must Read
Importing Packages Important - Must Read
Interfaces Important - Must Read
Defining an Interface Important - Must Read
Implementing Interfaces Important - Must Read
Nested Interfaces Important - Must Read
Applying Interfaces
Variables in Interfaces Important - Must Read
Interfaces Can Be Extended Important - Must Read
10 Exception Handling
Exception-Handling Fundamentals Important - Must Read
Exception Types Important - Must Read
Uncaught Exceptions Important - Must Read
Using try and catch Important - Must Read
Displaying a Description of an Exception Important - Must Read
Multiple catch Clauses Important - Must Read
Nested try Statements Important - Must Read
throw Important - Must Read
throws Important - Must Read
finally Important - Must Read
Java’s Built-in Exceptions Important - Must Read
Creating Your Own Exception Subclasses Important - Must Read
Chained Exceptions Important - Must Read
Using Exceptions Important - Must Read
11 Multithreaded Programming
The Java Thread Model Important - Must Read
Thread Priorities
The Thread Class and the Runnable Interface Important - Must Read
The Main Thread Important - Must Read
Creating a Thread Important - Must Read
Implementing Runnable Important - Must Read
Extending Thread Important - Must Read
Choosing an Approach Important - Must Read
Creating Multiple Threads Important - Must Read
Using isAlive( ) and join( ) Important - Must Read
Thread Priorities Important - Must Read
Synchronization Important - Must Read
Using Synchronized Methods Important - Must Read
The synchronized Statement Important - Must Read
Interthread Communication Important - Must Read
Deadlock Important - Must Read
Suspending, Resuming, and Stopping Threads Important - Must Read
The Modern Way of Suspending, Resuming and Stopping ThreadsImportant - Must Read
Using Multithreading
12 Enumerations, Autoboxing, and Annotations (Metadata)
Enumeration Fundamentals
The values( ) and valueOf( ) Methods
Java Enumerations Are Class Types
Enumerations Inherit Enum
Another Enumeration Example
Type Wrappers
Autoboxing and Methods
Autoboxing/Unboxing Occurs in Expressions
Autoboxing/Unboxing Boolean and Character Values
Autoboxing/Unboxing Helps Prevent Errors
AWord of Warning
Annotations (Metadata)
Annotation Basics
Specifying a Retention Policy
Obtaining Annotations at Run Time by Use of Reflection
The AnnotatedElement Interface
Using Default Values
Marker Annotations
Single-Member Annotations
The Built-In Annotations
Some Restrictions
13 I/O, Applets, and Other Topics
I/O Basics Important - Must Read
Streams Important - Must Read
Byte Streams and Character Streams Important - Must Read
The Predefined Streams
Reading Console Input Important - Must Read
Reading Characters Important - Must Read
Reading Strings Important - Must Read
Writing Console Output Important - Must Read
The PrintWriter Class Important - Must Read
Reading and Writing Files Important - Must Read
Applet Fundamentals
The transient and volatile Modifiers
Using instanceof
Native Methods
Problems with Native Methods
Using assert
Assertion Enabling and Disabling Options
Static Import
Invoking Overloaded Constructors Through this( )
14 Generics
What Are Generics? Important - Must Read
A Simple Generics Example Important - Must Read
Generics Work Only with Objects
Generic Types Differ Based on Their Type Arguments
How Generics Improve Type Safety
A Generic Class with Two Type Parameters
The General Form of a Generic Class
Bounded Types
Using Wildcard Arguments
Bounded Wildcards
Creating a Generic Method
Generic Constructors
Generic Interfaces
Raw Types and Legacy Code
Generic Class Hierarchies
Using a Generic Superclass
A Generic Subclass
Run-Time Type ComparisonsWithin a Generic Hierarchy
Overriding Methods in a Generic Class
Bridge Methods
Ambiguity Errors
Some Generic Restrictions
Type Parameters Can Be Instantiated
Restrictions on Static Members
Generic Array Restrictions
Generic Exception Restriction
Final Thoughts on Generics
15 String Handling
The String Constructors Important - Must Read
String Length Important - Must Read
Special String Operations
String Literals
String Concatenation
String Concatenation with Other Data Types
String Conversion and toString( ) Important - Must Read
Character Extraction
charAt( ) Important - Must Read
getChars( ) Important - Must Read
getBytes( )
toCharArray( )
String Comparison
equals( ) and equalsIgnoreCase( ) Important - Must Read
regionMatches( )
startsWith( ) and endsWith( )
equals( ) Versus == Important - Must Read
compareTo( )
Searching Strings
Modifying a String
substring( ) Important - Must Read
concat( )
replace( )
trim( ) Important - Must Read
Data Conversion Using valueOf( )
Changing the Case of Characters Within a String
Additional String Methods
StringBuffer Important - Must Read
StringBuffer Constructors Important - Must Read
length( ) and capacity( ) Important - Must Read
ensureCapacity( )
setLength( )
charAt( ) and setCharAt( )
getChars( )
append( )
insert( ) Important - Must Read
reverse( ) Important - Must Read
delete( ) and deleteCharAt( )
replace( )
substring( )
Additional StringBuffer Methods
16 Exploring java
Primitive Type Wrappers
Double and Float
Byte, Short, Integer, and Long
Recent Additions to Character for Unicode Code
Point Support
Memory Management
Executing Other Programs
Using currentTimeMillis( ) to Time Program Execution
Using arraycopy( )
Environment Properties
Using clone( ) and the Cloneable Interface
Transcendental Functions
Exponential Functions
Rounding Functions
Miscellaneous Math Methods
Thread, ThreadGroup, and Runnable
The Runnable Interface
ThreadLocal and InheritableThreadLocal
The CharSequence Interface
The Comparable Interface
The Appendable Interface
The Iterable Interface
The Readable Interface
17 java Collection Framework
Recent Changes to Collections
Generics Fundamentally Change the CollectionsImportant - Must Read
Autoboxing Facilitates the Use of Primitive Types
The For-Each Style for Loop
The Collection Interfaces Important - Must Read
The Collection Interface
The List Interface Important - Must Read
The Set Interface Important - Must Read
The SortedSet Interface
The NavigableSet Interface
The Queue Interface
The Deque Interface
The Collection Classes
The ArrayList Class
The LinkedList Class Important - Must Read
The HashSet Class
The LinkedHashSet Class
The TreeSet Class
The PriorityQueue Class
The ArrayDeque Class
The EnumSet Class
Accessing a Collection via an Iterator
Using an Iterator
The For-Each Alternative to Iterators
Storing User-Defined Classes in Collections
The RandomAccess Interface
Working with Maps
The Map Interfaces Important - Must Read
The NavigableMap Interface
The Map Classes
Using a Comparator
The Collection Algorithms
Why Generic Collections? Important - Must Read
The Legacy Classes and Interfaces
The Enumeration Interface
Using store( ) and load( )
Parting Thoughts on Collections
18 java – More Util Classes
Date Important - Must Read
The Observer Interface
An Observer Example
Timer and TimerTask
The Formatter Constructors
The Formatter Methods
Formatting Basics
Formatting Strings and Characters
Formatting Numbers
Formatting Time and Date
The %n and %% Specifiers
Specifying a Minimum Field Width
Specifying Precision
Using the Format Flags
Justifying Output
The Space, +, 0, and ( Flags
The Comma Flag
The # Flag
The Uppercase Option
Using an Argument Index
The Java printf( ) Connection
Scanner Important - Must Read
The Scanner Constructors
Scanning Basics
Some Scanner Examples
Setting Delimiters
Other Scanner Features
The ResourceBundle, ListResourceBundle,
andPropertyResourceBundle Classes
Miscellaneous Utility Classes and Interfaces
19 Input/Output: Exploring java
The Java I/O Classes and Interfaces
File Important - Must Read
Directories Important - Must Read
Using FilenameFilter
The listFiles( ) Alternative Important - Must Read
Creating Directories
The Closeable and Flushable Interfaces
The Stream Classes
The Byte Streams
InputStream Important - Must Read
OutputStream Important - Must Read
FileInputStream Important - Must Read
FileOutputStream Important - Must Read
Filtered Byte Streams
Buffered Byte Streams
DataOutputStream and DataInputStream
RandomAccessFile Important - Must Read
The Character Streams
BufferedReader Important - Must Read
BufferedWriter Important - Must Read
The Console Class
Using Stream I/O
Improving wc( ) Using a StreamTokenizer
ObjectOutputStream Important - Must Read
ObjectInputStream Important - Must Read
A Serialization Example Important - Must Read
Stream Benefits
20 Networking
Networking Basics Important - Must Read
The Networking Classes and Interfaces
InetAddress Important - Must Read
Factory Methods
Instance Methods
Inet4Address and Inet6Address
TCP/IP Client Sockets
The URI Class
TCP/IP Server Sockets
A Datagram Example
21 The Applet Class
Two Types of Applets
Applet Basics Important - Must Read
The Applet Class Important - Must Read
Applet Architecture Important - Must Read
An Applet Skeleton Important - Must Read
Applet Initialization and Termination Important - Must Read
Overriding update( )
Simple Applet Display Methods Important - Must Read
Requesting Repainting Important - Must Read
A Simple Banner Applet
Using the Status Window
Passing Parameters to Applets Important - Must Read
Improving the Banner Applet
getDocumentBase( ) and getCodeBase( )
AppletContext and showDocument( )
The AudioClip Interface
The AppletStub Interface
Outputting to the Console
22 Event Handling
Two Event Handling Mechanisms
The Delegation Event Model Important - Must Read
Event Sources
Event Listeners
Event Classes
The ActionEvent Class Important - Must Read
The AdjustmentEvent Class
The ComponentEvent Class
The ContainerEvent Class
The FocusEvent Class
The InputEvent Class
The ItemEvent Class Important - Must Read
The KeyEvent Class Important - Must Read
The MouseEvent Class Important - Must Read
The MouseWheelEvent Class
The TextEvent Class
The WindowEvent Class
Sources of Events
Event Listener Interfaces
The ActionListener Interface Important - Must Read
The AdjustmentListener Interface
The ComponentListener Interface
The ContainerListener Interface
The FocusListener Interface
The ItemListener Interface Important - Must Read
The KeyListener Interface Important - Must Read
The MouseListener Interface Important - Must Read
The MouseMotionListener Interface Important - Must Read
The MouseWheelListener Interface
The TextListener Interface
The WindowFocusListener Interface
The WindowListener Interface
Using the Delegation Event Model
Handling Mouse Events
Handling Keyboard Events
Adapter Classes Important - Must Read
Inner Classes Important - Must Read
Anonymous Inner Classes Important - Must Read
23 Introducing the AWT: Working with Windows, Graphics
AWT Classes
Window Fundamentals
Panel Important - Must Read
Frame Important - Must Read
Working with Frame Windows
Setting the Window’s Dimensions
Hiding and Showing a Window
Setting a Window’s Title
Closing a Frame Window
Creating a Frame Window in an Applet
Handling Events in a Frame Window
Creating a Windowed Program
Displaying Information Within a Window
Working with Graphics
Drawing Lines Important - Must Read
Drawing Rectangles Important - Must Read
Drawing Ellipses and Circles Important - Must Read
Drawing Arcs Important - Must Read
Drawing Polygons
Sizing Graphics
Working with Color Important - Must Read
Color Methods Important - Must Read
Setting the Current Graphics Color
A Color Demonstration Applet
Setting the Paint Mode
Working with Fonts
Determining the Available Fonts
Creating and Selecting a Font
Obtaining Font Information
Managing Text Output Using FontMetrics
Displaying Multiple Lines of Text
Centering Text
Multiline Text Alignment
24 Using AWT Controls, Layout Managers, and Menus
Control Fundamentals
Adding and Removing Controls
Responding to Controls
The HeadlessException
Labels Important - Must Read
Using Buttons Important - Must Read
Handling Buttons Important - Must Read
Applying Check Boxes Important - Must Read
Handling Check Boxes Important - Must Read
CheckboxGroup Important - Must Read
Choice Controls Important - Must Read
Handling Choice Lists Important - Must Read
Using Lists Important - Must Read
Handling Lists Important - Must Read
Managing Scroll Bars Important - Must Read
Handling Scroll Bars Important - Must Read
Using a TextField Important - Must Read
Handling a TextField Important - Must Read
Using a TextArea Important - Must Read
Understanding Layout Managers
FlowLayout Important - Must Read
BorderLayout Important - Must Read
Using Insets
GridLayout Important - Must Read
Menu Bars and Menus Important - Must Read
Dialog Boxes
Handling Events by Extending AWT Components
Extending Button
Extending Checkbox
Extending a Check Box Group
Extending Choice
Extending List
Extending Scrollbar
25 Images
File Formats
Image Fundamentals: Creating, Loading, and Displaying
Creating an Image Object
Loading an Image
Displaying an Image
Double Buffering
Memory image source
Cell Animation
Additional Imaging Classes
26 The Concurrency Utilities
The Concurrent API Packages
Using Synchronization Objects
Using an Executor
A Simple Executor Example
Using Callable and Future
The TimeUnit Enumeration
The Concurrent Collections
Atomic Operations
The Concurrency Utilities Versus Java’s Traditional Approach
27 NIO, Regular Expressions, and Other Packages
The Core Java API Packages
NIO Fundamentals
Charsets and Selectors
Using the NIO System
Is NIO the Future of I/O Handling?
Regular Expression Processing
Regular Expression Syntax
Demonstrating Pattern Matching
Two Pattern-Matching Options
Exploring Regular Expressions
Remote Method Invocation (RMI)
A Simple Client/Server Application Using RMI
Text Formatting
DateFormat Class
SimpleDateFormat Class
Part III Software Development Using Java
28 Java Beans
What Is a Java Bean? Important - Must Read
Advantages of Java Beans Important - Must Read
Design Patterns for Properties
Design Patterns for Events
Methods and Design Patterns
Using the BeanInfo Interface
Bound and Constrained Properties
The Java Beans API
A Bean Example
29 Introducing Swing
The Origins of Swing Important - Must Read
Swing Is Built on the AWT Important - Must Read
Two Key Swing Features Important - Must Read
Swing Components Are Lightweight Important - Must Read
Swing Supports a Pluggable Look and Feel Important - Must Read
The MVC Connection Important - Must Read
Components and Containers
The Top-Level Container Panes
The Swing Packages
A Simple Swing Application
Event Handling
Create a Swing Applet
Painting in Swing
Painting Fundamentals
Compute the Paintable Area
A Paint Example
30 Exploring Swing
JLabel and ImageIcon
The Swing Buttons
Check Boxes
Radio Buttons
Continuing Your Exploration of Swing
31 Servlets
The Life Cycle of a Servlet
Using Tomcat for Servlet Development
A Simple Servlet
Create and Compile the Servlet Source Code
Start Tomcat
Start a Web Browser and Request the Servlet
The Servlet API
The javax
The Servlet Interface
The ServletConfig Interface
The ServletContext Interface
The ServletRequest Interface
The ServletResponse Interface
The GenericServlet Class
The ServletInputStream Class
The ServletOutputStream Class
The Servlet Exception Classes
Reading Servlet Parameters
The javax
The HttpServletRequest Interface
The HttpServletResponse Interface
The HttpSession Interface
The HttpSessionBindingListener Interface
The Cookie Class
The HttpServlet Class
The HttpSessionEvent Class
The HttpSessionBindingEvent Class
Handling HTTP Requests and Responses
Handling HTTP GET Requests
Handling HTTP POST Requests
Using Cookies
Session Tracking
Part IV Applying Java
32 Financial Applets and Servlets
Finding the Payments for a Loan
The RegPay Fields
The init( ) Method
The makeGUI( ) Method
The actionPerformed( ) Method
The compute( ) Method
Finding the Future Value of an Investment
Finding the Initial Investment Required to Achieve a Future Value
Finding the Initial Investment Needed for a Desired Annuity
Finding the Maximum Annuity for a Given Investment
Finding the Remaining Balance on a Loan
Creating Financial Servlets
Converting the RegPay Applet into a Servlet
The RegPayS Servlet
Some Things to Try
33 Creating a Download Manager in Java
Understanding Internet Downloads
An Overview of the Download Manager
The Download Class
The Download Variables
The Download Constructor
The download( ) Method
The run( ) Method
The stateChanged( ) Method
Action and Accessor Methods
The ProgressRenderer Class
The DownloadsTableModel Class
The addDownload( ) Method
The clearDownload( ) Method
The getColumnClass( ) Method
The getValueAt( ) Method
The update( ) Method
The DownloadManager Class
The DownloadManager Variables
The DownloadManager Constructor
The verifyUrl( ) Method
The tableSelectionChanged( ) Method
The updateButtons( ) Method
Handling Action Events
Compiling and Running the Download Manager
Enhancing the Download Manager