Table of Contents
Select one of the links below to reach the section in this Table of Contents for that trail.
Copyright
Getting Started
Writing Java Programs
Writing Applets
Creating a User Interface
Custom Networking and Security
The Java Development Environment
Integrating Native Methods into Java Programs
How the Java Language Differs from C and C++
Troubleshooting
Copyright
Getting Started
The "Hello World" Application
The "Hello World" Applet
Writing Java Programs
Object-Oriented Programming Concepts: A Primer
What is an Object?
What are Messages?
What are Classes?
What is Inheritance?
Where Can I Get More Information?
The Anatomy of a Java Application
Comparison of DateApp and "Hello World"
Defining a Class
The main() Method
Using Objects in Java Programs
Declaring, Instantiating and Initializing an Object
Class Members vs. Instance Members
Saving, Compiling and Running an Application
The Nuts and Bolts of the Java Language
A Simple Class Definition
The main() Method
Introducing Exceptions
Variables and Data Types
Control Flow Statements
The Standard Input Stream
Operators
The Standard Output Stream
Character Data
Running the Application
Objects, Classes, and Interfaces
The Life Cycle of an Object
Creating an Object
Using an Object
Garbage Collection of Unused Objects
Creating Your Own Classes
The Class Declaration
The Class Body
Constructors
Writing a finalize() Method
Declaring a Member Variable
A Variable's Type
A Variable's Name
Other Variable Declaration Components
Controlling Access to a Class's Variables
The Scoop on Instance and Class Variables
Declaring a Constant
Declaring a Transient Variable
Declaring a Volatile Variable
Writing Methods
The Method Declaration
Returning a Value from a Method
A Method's Name
Other Method Declaration Stuff
Controlling Access to a Class's Methods
The Scoop on Instance and Class Methods
Passing Information into a Method
Summary of A Method Declaration
The Method Body
Subclasses, Superclasses, and Inheritance
Creating a Subclass
Overriding Methods
Writing Final Classes and Methods
Writing Abstract Classes and Methods
Creating and Using Interfaces
Creating an Interface
Using an Interface
The String and StringBuffer Classes
Why Two String Classes?
Creating Strings and StringBuffers
Accessor Methods
More Accessor Methods
Modifying StringBuffers
Converting Objects to Strings
Converting Strings to Numbers
Strings and the Java Compiler
Command Line Arguments
The Space Character Separates Command Line Arguments
Conventions
Parsing Command Line Arguments
Threads of Control
What Are Threads?
A Simple Thread Example
Thread Attributes
Thread Body
The Clock Applet
Thread State
Thread Priority
Daemon Threads
Thread Group
The ThreadGroup Class
Multithreaded Programs
Synchronizing Threads
Monitors
Java Monitors are Re-entrant
The notify() and wait() Methods
Fairness, Starvation, and Deadlock
Deadlock and the Dining Philosophers
Summary
Input and Output Streams
Your First Encounter with I/O in Java
Overview of java.io's Input and Output Streams
Using Input and Output Streams
Working with Filtered Streams
Using DataInputStream and DataOutputStream
Writing Your Own Filtered Streams
Working with Random Access Files
Using Random Access Files
Writing Filters for RandomAccessFiles and DataInput/DataOutput
Handling Errors using Exceptions
What's an Exception and Why Do I Care?
Your First Encounter with Java Exceptions
Java's Catch or Declare Requirement
Dealing with Exceptions
The Example
Catching and Handling Exceptions
The try Block
The catch Block(s)
The finally Block
Putting It All Together
Declaring the Exceptions Thrown by a Method
How to Throw Exceptions
The throw Statement
The Throwable Class and Its Subclasses
Creating Your Own Exception Classes
Runtime Exceptions--The Controversy
Writing Applets
Overview of Applets
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Using UI Components
Threads in Applets
Example
Saving, Compiling, and Running an Applet
Creating an Applet User Interface
Creating a GUI
Playing Sounds
Defining and Using Applet Parameters
Deciding Which Parameters to Support
Writing the Code to Support Parameters
Giving Information about Parameters
Reading System Properties
Displaying Short Status Strings
Displaying Diagnostics to the Standard Output
Communicating with Other Programs
Sending Messages to Other Applets
Working with a Server-Side Application
Other Communication
Understanding Applet Capabilities and Restrictions
Security Restrictions
What Can't Applets Do?
Working around Security Restrictions
Applet Capabilities
Before You Ship that Applet
Creating a User Interface
Overview of the Java UI
AWT Components
Other AWT Classes
The Anatomy of a GUI-Based Program
Classes in the Example Program
The Component Hierarchy
Drawing
Event Handling
Using Components, the GUI Building Blocks
Using the AWT Components
General Rules for Using Components
How to Use Buttons
How to Use Canvases
How to Use Checkboxes
How to Use Choices
How to Use Dialogs
How to Use Frames
How to Use Labels
How to Use Lists
How to Use Menus
How to Use Panels
How to Use Scrollbars
How to Use TextAreas and TextFields
Details of the Component Architecture
Common Component Problems (and Their Solutions)
Laying Out Components within a Container
Using Layout Managers
General Rules for Using Layout Managers
How to Use BorderLayout
How to Use CardLayout
How to Use FlowLayout
How to Use GridLayout
How to Use GridBagLayout
Specifying Constraints
The Applet Example Explained
Creating a Custom Layout Manager
Doing Without a Layout Manager (Absolute Positioning)
Common Layout Problems (and Their Solutions)
Working with Graphics
Overview of AWT Graphics Support
Using Graphics Primitives
Drawing Simple Shapes
Working with Text
Using Images
Loading Images
Displaying Images
Manipulating Images
Performing Animation
Creating the Animation Loop
Animating Graphics
Eliminating Flashing
Overriding the update() Method
Double Buffering
Moving an Image Across the Screen
Displaying a Sequence of Images
Improving the Appearance and Performance of Image Animation
Common Graphics Problems (and Their Solutions)
Custom Networking and Security
What You May Already Know About Networking in Java
Working with URLs
What is a URL?
Creating a URL
Parsing a URL
Reading Directly from a URL
Connecting to a URL
Reading from and Writing to a URLConnection
Advanced URLs
The URLEncoder Helper Class
All about Sockets
What is a Socket?
Reading from and Writing to a Socket
Writing the Server Side of a Socket
All about Datagrams
What is a Datagram?
Writing a Datagram Client and Server
Providing Your Own Security Manager
Introducing the Security Manager
Writing a Security Manager
Installing your Security Manager
More About the SecurityManager Class
The Java Development Environment
Package Tour
The Java Language Package
The Java I/O Package
Input Streams
Output Streams
The Java Utility Package
Managing Your Programming Environment
The CLASSPATH Environment Variable
Creating and Using Packages
Roll Your Own Packages
Using Objects and Classes from Other Packages
Clarifying Object and Class Names
Directory Structure
System
Using the System Class
Standard Output and Error Streams
Using System-Dependent Resources
Miscellaneous System Methods
Integrating Native Methods into Java Programs
Step By Step
Step 1: Write the Java Code
Step 2: Compile the Java Code
Step 3: Create the .h File
Step 4: Create a Stubs File
Step 5: Write the C Function
Step 6: Create a Dynamically Loadable Library
Step 7: Run the Program
A Comprehensive Example
How the Java Language Differs from C and C++
C Data Types Not Supported By the Java Language
Operators
Java Command Line Arguments from C and C++
Java Strings are First-Class Objects
Miscellaneous Differences
Troubleshooting
Troubleshooting Compiler Problems
Troubleshooting Interpreter Problems