Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Java All-in-One Desk Reference For Dummies
About the Author
Dedication
Author’s Acknowledgments
Contents at a Glance
Table of Contents
Introduction
About This Book
How to Use This Book
How This Book Is Organized
Icons Used in This Book
Where to Go from Here
About This Book
How to Use This Book
How This Book Is Organized
Icons Used in This Book
Where to Go from Here
Book I: Java Basics
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Chapter 4: Using Eclipse
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Chapter 4: Using Eclipse
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Book II: Programming Basics
Chapter 1: Java Programming Basics
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (Or, Using Loops)
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Chapter 1: Java Programming Basics
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (Or, Using Loops)
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Book III: Object-Oriented Programming
Chapter 1: Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
Chapter 2: Making Your Own Classes
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Chapter 3: Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4: Using Subclasses and Inheritance
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Chapter 5: Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Chapter 6: Using the Object and Class Classes
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
Chapter 7: Using Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Chapter 8: Packaging and Documenting Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Chapter 1: Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
Chapter 2: Making Your Own Classes
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Chapter 3: Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4: Using Subclasses and Inheritance
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Chapter 5: Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Chapter 6: Using the Object and Class Classes
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
Chapter 7: Using Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Chapter 8: Packaging and Documenting Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Book IV: Strings, Arrays, and Collections
Chapter 1: Working with Strings
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Chapter 2: Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Chapter 3: Using the ArrayList Class
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4: Using the LinkedList Class
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5: Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Chapter 1: Working with Strings
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Chapter 2: Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Chapter 3: Using the ArrayList Class
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4: Using the LinkedList Class
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5: Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Book V: Programming Techniques
Chapter 1: Programming Threads
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Chapter 2: Network Programming
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Chapter 3: Using Regular Expressions
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
Chapter 4: Using Recursion
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
Chapter 1: Programming Threads
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Chapter 2: Network Programming
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Chapter 3: Using Regular Expressions
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
Chapter 4: Using Recursion
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
Book VI: Swing
Chapter 1: Swinging into Swing
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Chapter 2: Handling Events
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Chapter 3: Getting Input from the User
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Chapter 4: Choosing from a List
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Chapter 5: Using Layout Managers
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Chapter 1: Swinging into Swing
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Chapter 2: Handling Events
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Chapter 3: Getting Input from the User
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Chapter 4: Choosing from a List
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Chapter 5: Using Layout Managers
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Book VII: Web Programming
Chapter 1: Creating Applets
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Chapter 2: Creating Servlets
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Chapter 3: Using Java Server Pages
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Chapter 4: Using JavaBeans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
Chapter 1: Creating Applets
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Chapter 2: Creating Servlets
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Chapter 3: Using Java Server Pages
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Chapter 4: Using JavaBeans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
Book VIII: Files and Databases
Chapter 1: Working with Files
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Chapter 2: Using File Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Chapter 3: Database for $100, Please
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
Chapter 4: Using JDBC to Connect to a Database
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Chapter 5: Working with XML
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
Chapter 1: Working with Files
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Chapter 2: Using File Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Chapter 3: Database for $100, Please
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
Chapter 4: Using JDBC to Connect to a Database
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Chapter 5: Working with XML
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
Book IX: Fun and Games
Chapter 1: Fun with Fonts and Colors
Working with Fonts
Working with Color
Working with Fonts
Working with Color
Chapter 2: Drawing Shapes
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Chapter 3: Using Images and Sound
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Chapter 4: Animation and Game Programming
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Chapter 1: Fun with Fonts and Colors
Working with Fonts
Working with Color
Working with Fonts
Working with Color
Chapter 2: Drawing Shapes
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Chapter 3: Using Images and Sound
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Chapter 4: Animation and Game Programming
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Index
About the Author
Dedication
Author’s Acknowledgments
Contents at a Glance
Table of Contents
Introduction
About This Book
How to Use This Book
How This Book Is Organized
Icons Used in This Book
Where to Go from Here
About This Book
How to Use This Book
How This Book Is Organized
Icons Used in This Book
Where to Go from Here
Book I: Java Basics
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Chapter 4: Using Eclipse
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
What Is Java, and Why Is It So Great?
Comparing Java to Other Languages
Important Features of the Java Language
On the Downside: Java’s Weaknesses
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Downloading and Installing the Java Development Kit
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running an Applet
Chapter 4: Using Eclipse
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Understanding Projects
Creating a Simple Project
Adding a Class File
Running a Program
Debugging a Java Program
Refactoring Your Code
Book II: Programming Basics
Chapter 1: Java Programming Basics
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (Or, Using Loops)
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Chapter 1: Java Programming Basics
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Looking At the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Declaring Variables
Initializing Variables
Using Final Variables (Or Constants)
Working with Primitive Data Types
Using Reference Types
Working with Strings
Converting and Casting Numeric Data
Understanding Scope
Shadowing Variables
Printing Data with System. out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Using Simple Boolean Expressions
Using If Statements
Mr. Spock’s Favorite Operators (The Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (Or, Using Loops)
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
do-while Loops
Validating Input from the User
The Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
else-if Monstrosities
A Better Version of the Voter Machine Error Decoder Program
Using the switch Statement
A Boring Business Example Complete with Flowchart
Putting if Statements Inside switch Statements
Creating Character Cases
Falling through the Cracks
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Using Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Pre-emptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Book III: Object-Oriented Programming
Chapter 1: Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
Chapter 2: Making Your Own Classes
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Chapter 3: Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4: Using Subclasses and Inheritance
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Chapter 5: Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Chapter 6: Using the Object and Class Classes
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
Chapter 7: Using Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Chapter 8: Packaging and Documenting Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Chapter 1: Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
What Is Object-Oriented Programming?
Understanding Objects
The Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
Chapter 2: Making Your Own Classes
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Declaring a Class
Working with Members
Getters and Setters
Overloading Methods
Creating Constructors
More Uses for this
Using Initializers
Chapter 3: Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4: Using Subclasses and Inheritance
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using this and super in Your Subclasses
Inheritance and Constructors
Using final
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Chapter 5: Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Chapter 6: Using the Object and Class Classes
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
Chapter 7: Using Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Chapter 8: Packaging and Documenting Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Working with Packages
Putting Your Classes in a JAR File
Using JavaDoc to Document Your Classes
Book IV: Strings, Arrays, and Collections
Chapter 1: Working with Strings
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Chapter 2: Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Chapter 3: Using the ArrayList Class
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4: Using the LinkedList Class
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5: Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Chapter 1: Working with Strings
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Reviewing Strings
Using the String Class
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Chapter 2: Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Two-Dimensional Arrays
A Fun but Complicated Example: A Chess Board
Using the Arrays Class
Chapter 3: Using the ArrayList Class
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
The ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4: Using the LinkedList Class
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
The LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5: Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard Type Parameters
A Generic Queue Class
Book V: Programming Techniques
Chapter 1: Programming Threads
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Chapter 2: Network Programming
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Chapter 3: Using Regular Expressions
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
Chapter 4: Using Recursion
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
Chapter 1: Programming Threads
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Synchronizing Methods
Threadus Interruptus
Chapter 2: Network Programming
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Understanding Network Programming
Getting Information about Internet Hosts
Creating Network Server Applications
Introducing BART
BartServer 2.0
Chapter 3: Using Regular Expressions
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
A Program for Experimenting with Regular Expressions
Basic Character Matching
Using Regular Expressions in Java Programs
Chapter 4: Using Recursion
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
The Classic Factorial Example
Displaying Directories
Writing Your Own Sorting Routine
Book VI: Swing
Chapter 1: Swinging into Swing
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Chapter 2: Handling Events
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Chapter 3: Getting Input from the User
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Chapter 4: Choosing from a List
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Chapter 5: Using Layout Managers
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Chapter 1: Swinging into Swing
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Some Important Swing Concepts You Need to Know
I’ve Been Framed!
Hello, World! in Swing
Positioning the Frame On-Screen
Using the JPanel Class
Using Labels
Creating Buttons
A Word about the Layout of Components
Chapter 2: Handling Events
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Examining Events
Handling Events
The ClickMe Program
Using Inner Classes to Listen for Events
Adding an Exit Button
Catching the WindowClosing Event
The ClickMe Program Revisited
Chapter 3: Getting Input from the User
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Using Text Fields
Using Text Areas
Using Check Boxes
Using Radio Buttons
Using Borders
Designing a Pizza-Ordering Program
Using Sliders
Chapter 4: Choosing from a List
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Using Combo Boxes
Using Lists
Using Spinners
Using Trees
Chapter 5: Using Layout Managers
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Introducing Layout Managers
Using Flow Layout
Using Border Layout
Using Box Layout
Using Grid Layout
Using GridBag Layout
Book VII: Web Programming
Chapter 1: Creating Applets
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Chapter 2: Creating Servlets
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Chapter 3: Using Java Server Pages
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Chapter 4: Using JavaBeans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
Chapter 1: Creating Applets
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Understanding Applets
The JApplet Class
Looking At a Sample Applet
Creating an HTML Page for an Applet
Testing an Applet
Chapter 2: Creating Servlets
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Understanding Servlets
Using Tomcat
Creating a Simple Servlet
Running a Servlet
An Improved HelloWorld Servlet
Getting Input from the User
Using Classes in a Servlet
Chapter 3: Using Java Server Pages
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Understanding Java Server Pages
Using Page Directives
Using Expressions
Using Scriptlets
Using Declarations
Using Classes
Chapter 4: Using JavaBeans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
What Is a JavaBean?
Looking Over a Sample Bean
Using Beans with JSP Pages
Scoping Your Beans
Book VIII: Files and Databases
Chapter 1: Working with Files
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Chapter 2: Using File Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Chapter 3: Database for $100, Please
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
Chapter 4: Using JDBC to Connect to a Database
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Chapter 5: Working with XML
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
Chapter 1: Working with Files
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Using the File Class
Using Command-Line Parameters
Choosing Files in a Swing Application
Chapter 2: Using File Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Understanding Streams
Reading Character Streams
Writing Character Streams
Reading Binary Streams
Writing Binary Streams
Chapter 3: Database for $100, Please
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
What Is a Relational Database?
What Is SQL, and How Do You Pronounce It?
SQL Statements
Creating a SQL Database
Querying a Database
Updating and Deleting Rows
Chapter 4: Using JDBC to Connect to a Database
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Setting Up a Driver
Connecting to a Database
Querying a Database
Updating SQL Data
Using an Updatable RowSet Object
Chapter 5: Working with XML
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
What Exactly Is XML, Anyway?
Using a DTD
Processing XML in Two Ways
Reading a DOM Document
Reading DOM Nodes
Putting It All Together: A Program That Lists Movies
Book IX: Fun and Games
Chapter 1: Fun with Fonts and Colors
Working with Fonts
Working with Color
Working with Fonts
Working with Color
Chapter 2: Drawing Shapes
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Chapter 3: Using Images and Sound
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Chapter 4: Animation and Game Programming
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Chapter 1: Fun with Fonts and Colors
Working with Fonts
Working with Color
Working with Fonts
Working with Color
Chapter 2: Drawing Shapes
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Getting a Graphics Context
Drawing Shapes
Creating Shapes
Filling Shapes
Rotating and Translating
Drawing Text
Letting the User Draw on a Component
Chapter 3: Using Images and Sound
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Using Images
Using the ImageIcon Class
Using the Image Class
Playing Sounds and Making Music
Chapter 4: Animation and Game Programming
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Animating a Sprite
What about Double Buffering?
Bouncing the Ball
Bouncing a Bunch of Balls
Creating Collidable Balls
Playing Games
Index
← Prev
Back
Next →
← Prev
Back
Next →