The JavaTM Tutorial


The Really Big Index
A list of all content pages in the The JavaTM Tutorial

Here's a list of all of the trails in The Java Tutorial. Each item in this list links to the location on this page where a particular trail's lessons and pages are listed in order.

Trails Published in The Java Tutorial Second Edition

Trails Published inThe JFC Swing Tutorial Trails Published inThe Java Tutorial Continued Trails Available Only Online

Trail: Getting Started

Your First Cup of Java
Your First Cup of Java (for Win32)
Your First Cup of Java (for UNIX)
The Java Phenomenon
What Is Java?
What Can Java Do?
How Will Java Change My Life?
The "Hello World" Application
The Anatomy of a Java Application
    Comments in Java Code
    Defining a Class
    The main Method
    Using Classes and Objects
The "Hello World" Applet
The Anatomy of a Java Applet
    Importing Classes and Packages
    Defining an Applet Subclass
    Implementing Applet Methods
    Running an Applet
Solving Common Compiler and Interpreter Problems

Trail: Learning the Java Language

Object-Oriented Programming Concepts
What Is an Object?
What Is a Message?
What Is a Class?
What Is Inheritance?
What Is an Interface?
How Do These Concepts Translate into Code?
Questions and Exercises: Object-Oriented Concepts
The Nuts and Bolts of the Java Language
Variables
    Data Types
    Variable Names
    Scope
    Variable Initialization
    Final Variables
    Summary of Variables
    Questions and Exercises: Variables
Operators
    Arithmetic Operators
    Relational and Conditional Operators
    Shift and Logical Operators
    Assignment Operators
    Ternary Operator
    Summary of Operators
    Questions and Exercises: Operators
Expressions, Statements, and Blocks
Control Flow Statements
    The while and do-while Statements
    The for Statement
    The if-else Statement
    The switch Statement
    Exception Handling Statements
    Branching Statements
    Summary of Control Flow Statements
    Questions and Exercises: Control Flow
Objects and Classes in Java
The Life Cycle of an Object
    Creating Objects
    Using Objects
    Cleaning Up Unused Objects
Creating Classes
    The Class Declaration
    The Class Body
    Providing Constructors for Your Classes
    Declaring Member Variables
    Implementing Methods
        Details of a Method Declaration
        Passing Information into a Method
        The Method Body
    Controlling Access to Members of a Class
    Understanding Instance and Class Members
Reality Break! The Spot Applet
    Extending a Class
    Implementing an Interface
    Using an Inner Class to Implement an Adapter
Summary
Data Structures
Arrays and Strings
More Features of the Java Language
Managing Inheritance
    Understanding Inheritance
        Overriding Methods
    Being a Descendent of Object
    Writing Final Classes and Methods
    Writing Abstract Classes and Methods
Creating Interfaces
    What Is an Interface?
    Defining an Interface
    Implementing the Sleeper Interface
    Using an Interface as a Type
    Warning! Interfaces Cannot Grow
Implementing Nested Classes
    Inner Classes
Creating and Using Packages
    Creating a Package
    Using Package Members
    Managing Source and Class Files
Solving Common Coding Problems

Trail: Writing Applets

Overview of Applets
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Methods for Adding UI Components
What Applets Can and Can't Do
Test Driving an Applet
Summary
Taking Advantage of the Applet API
Finding and Loading Data Files
Displaying Short Status Strings
Displaying Documents in the Browser
Sending Messages to Other Applets
Playing Sounds
Defining and Using Applet Parameters
    Deciding Which Parameters to Support
    Writing the Code to Support Parameters
    Giving Information about Parameters
Using the APPLET Tag
Practical Considerations when Writing Applets
Security Restrictions
Creating a User Interface
    Using the AWT to Create a GUI
    Displaying Diagnostics to the Standard Output and Error Streams
Getting System Properties
Threads in Applets
    Threads in Applets: Examples
Working with a Server-Side Application
    A Simple Network Client Applet
    Using a Server to Work Around Security Restrictions
Finishing an Applet
Before You Ship That Applet
The Perfectly Finished Applet
Solving Common Applet Problems

Trail: Essential Java Classes

Using String and StringBuffer
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
Setting Program Attributes
Using Properties to Manage Program Attributes
Command-Line Arguments
Accessing System Resources
Using the System Class
The Standard I/O Streams
System Properties
Forcing Finalization and Garbage Collection
Providing Your Own Security Manager
    Introducing the Security Manager
    Writing a Security Manager
    Installing Your Security Manager
    Deciding What SecurityManager Methods to Override
Miscellaneous System Methods
The Runtime Object
Handling Errors with Exceptions
What's an Exception and Why Do I Care?
Your First Encounter with Java Exceptions
Java's Catch or Specify Requirement
Dealing with Exceptions
    The ListOfNumbers Example
    Catching and Handling Exceptions
        The try Block
        The catch Block(s)
        The finally Block
        Putting It All Together
    Specifying 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
Doing Two or More Tasks At Once: Threads
What Is a Thread?
Customizing a Thread's run Method
    Subclassing Thread and Overriding run
    Implementing the Runnable Interface
The Life Cycle of a Thread
Understanding Thread Priority
Synchronizing Threads
    The Producer/Consumer Example
    Locking an Object
        Reaquiring a Lock
    Using the notifyAll and wait Methods
    Avoiding Starvation and Deadlock
Grouping Threads
    The ThreadGroup Class
Summary
Reading and Writing (but no 'rithmetic)
Overview of I/O Streams
Using the Data Sink Streams
    How to Use File Streams
    How to Use Pipe Streams
Using the Processing Streams
    How to Concatenate Files
    Working with Filtered Streams
        How to Use DataInputStream and DataOutputStream
        Writing Your Own Filtered Streams
Object Serialization
    Serializing Objects
    Providing Object Serialization for Your Classes
Working with Random Access Files
    Using Random Access Files
    Writing Filters for Random Access Files
And the Rest . . .

Trail: Custom Networking

Overview of Networking
What You May Already Know About Networking in Java
Networking Basics
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
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
Broadcasting to Multiple Recipients

Trail: JDK(TM) 1.1 -- And Beyond!

What's New in 1.1?
Internationalization
Security and Signed Applets
AWT Enhancements
JavaBeans(tm)
JAR File Format
Networking Enhancements
I/O Enhancements
Math Package
Remote Method Invocation
Reflection
Java Database Connectivity
Inner Classes
Java Native Interface
Performance Enhancements
Miscellaneous
Migrating to 1.1
When Should the Great Migration Occur?
What Does Deprecation Mean?
How to Convert Your Program
    Special Coding Techniques
    How to Convert Code that Uses I/O
    How to Convert Code that Uses the AWT
Lists and Tables
    Alternatives to Deprecated Methods in java.lang, java.net, and java.util
    Character Streams versus Byte Streams
    Alternatives to Deprecated Classes and Methods in java.io
    Alternatives to Deprecated Methods in the AWT
    List of Deprecated Classes and Methods in JDK 1.1
    Event-Conversion Table
    Packages New for 1.1
    Classes New for 1.1
    Changes to the Java Language
JDK 1.1 Compability
    Incompatible Changes in the 1.1 AWT API
A Preview of Things to Come
Security Enhancements
Java Foundation Classes (JFC)
Collections
JavaBeans Enhancements
Input Method Framework
Package Version Identification
RMI Enhancements
Serialization Enhancements
Weak References
Audio Enhancements
Java IDL
Performance Enhancements
Threads Changes

Trail: Creating a GUI with JFC/Swing

Getting Started with Swing
About the JFC and Swing
Compiling and Running Swing Programs
    Compiling and Running Swing Programs (Java 2 Platform)
    Compiling and Running Swing Programs (JDK 1.1)
Running Swing Applets
A Quick Tour of a Swing Application's Code
Swing Features and Concepts
Swing Components and the Containment Hierarchy
Layout Management
Event Handling
Painting
Threads and Swing
More Swing Features and Concepts
The Anatomy of a Swing-Based Program
Using Swing Components
A Visual Index to the Swing Components
The JComponent Class
Using Top-Level Containers
    How to Make Frames (Main Windows)
    How to Make Dialogs
    How to Make Applets
Using Intermediate Swing Containers
    How to Use Panels
    How to Use Scroll Panes
    How to Use Split Panes
    How to Use Tabbed Panes
    How to Use Tool Bars
    How to Use Internal Frames
    How to Use Layered Panes
    How to Use Root Panes
Using Atomic Components
    How to Use Buttons, Check Boxes, and Radio Buttons
    How to Use Color Choosers
    How to Use Combo Boxes
    How to Use File Choosers
    How to Use Labels
    How to Use Lists
    How to Use Menus
    How to Monitor Progress
    How to Use Sliders
    How to Use Tables
    Using Text Components
        An Example of Using Each Text Component
        General Rules for Using Text Components
        How to Use Text Fields
        Concepts: About Editor Panes and Text Panes
        Summary of Text
    How to Use Tool Tips
    How to Use Trees
Solving Common Component Problems
Using Other Swing Features
How to Use Actions
How to Support Assistive Technologies
How to Use Borders
How to Use Icons
How to Set the Look and Feel
How to Use Threads
How to Use Timers
Solving Common Problems Using Other Swing Features
Laying Out Components Within a Container
Using Layout Managers
    General Rules for Using Layout Managers
    How to Use BorderLayout
    How to Use BoxLayout
    How to Use CardLayout
    How to Use FlowLayout
    How to Use GridLayout
    How to Use GridBagLayout
        How to Use GridBagLayout: Specifying Constraints
        How to Use GridBagLayout: The Example Explained
Creating a Custom Layout Manager
Doing Without a Layout Manager (Absolute Positioning)
Solving Common Layout Problems
Writing Event Listeners
Some Simple Event-Handling Examples
General Information about Writing Event Listeners
Listeners Supported by Swing Components
Implementing Listeners for Commonly Handled Events
    How to Write an Action Listener
    How to Write a Caret Listener
    How to Write a Change Listener
    How to Write a Component Listener
    How to Write a Container Listener
    How to Write a Document Listener
    How to Write a Focus Listener
    How to Write an Internal Frame Listener
    How to Write an Item Listener
    How to Write a Key Listener
    How to Write a List Data Listener
    How to Write a List Selection Listener
    How to Write a Mouse Listener
    How to Write a Mouse-Motion Listener
    How to Write a Table Model Listener
    How to Write a Tree Expansion Listener
    How to Write a Tree Model Listener
    How to Write a Tree Selection Listener
    How to Write a Tree-Will-Expand Listener
    How to Write an Undoable Edit Listener
    How to Write a Window Listener
Summary of Listener API
Solving Common Event-Handling Problems
Working with Graphics
Overview of Custom Painting
Using Graphics Primitives
    Painting Shapes
    Working with Text
Using Images
    Loading Images
    Displaying Images
Performing Animation
    Creating an Animation Loop with Timer
    Moving an Image Across the Screen
    Displaying a Sequence of Images
    Improving the Appearance and Performance of Image Animation
Solving Common Graphics Problems
Converting to Swing
Why to Convert
How to Convert
Conversion Resources
    Swing Replacements for AWT Components
    General Conversion Tips
    Component-Specific Conversion Tips
    Some Conversion Examples
Solving Common Conversion Problems

Trail: Overview

Essential Classes
Advanced GUI Building
Networking and Connectivity
Packaging
Advanced Language Topics
Tables of JDK Features

Trail: Collections

Introduction
Interfaces
The Collection Interface
The Set Interface
The List Interface
The Map Interface
Object Ordering
The SortedSet Interface
The SortedMap Interface
Implementations
General Purpose Implementations
Wrapper Implementations
Convenience Implementations
Algorithms
Custom Implementations
Interoperability
Compatibility
API Design
Solving Common Collections Problems

Trail: Internationalization

Introduction
A Quick Example
    Before Internationalization
    After Internationalization
    Running the Sample Program
    Internationalizing the Sample Program
Checklist
Setting the Locale
Creating a Locale
Identifying Available Locales
The Scope of a Locale
Isolating Locale-Specific Data
About the ResourceBundle Class
Preparing to Use a ResourceBundle
Backing a ResourceBundle with Properties Files
Using a ListResourceBundle
Formatting
Numbers and Currencies
    Using Predefined Formats
    Customizing Formats
Dates and Times
    Using Predefined Formats
    Customizing Formats
    Changing Date Format Symbols
Messages
    Dealing with Compound Messages
    Handling Plurals
Working with Text
Checking Character Properties
Comparing Strings
    Performing Locale-Independent Comparisons
    Customizing Collation Rules
    Improving Collation Performance
Detecting Text Boundaries
    About the BreakIterator Class
    Character Boundaries
    Word Boundaries
    Sentence Boundaries
    Line Boundaries
Converting Non-Unicode Text
    Byte Encodings and Strings
    Character and Byte Streams

Trail: 2D Graphics

Overview of the Java 2D API
Java 2D Rendering
Coordinate Systems
Shapes
Text
Images
Printing
Displaying Graphics with Graphics2D
Stroking and Filling Graphics Primitives
Transforming Shapes, Text, and Images
Clipping the Drawing Region
Compositing Graphics
Controlling Rendering Quality
Constructing Complex Shapes from Geometry Primitives
Supporting User Interaction
Working with Text and Fonts
Creating and Deriving Fonts
Drawing Multiple Lines of Text
Manipulating and Displaying Images
Immediate-Mode Imaging with BufferedImage
Filtering a BufferedImage
Using a BufferedImage for Double Buffering
Printing
Overview of Printing in Java
Printing the Contents of a Component
Displaying a Page Setup Dialog
Printing a Collection of Pages
Solving Common 2D Graphics Problems

Trail: Sound

Overview
Playing Sounds
Solving Common Sound Problems

Trail: JavaBeans(TM)

JavaBeans Concepts and the Beans Development Kit
JavaBeans Concepts
The Beans Development Kit
Using the BeanBox
Starting and Using the BeanBox
The BeanBox Menus
Using the BeanBox to Generate Applets
Writing a Simple Bean
Properties
Simple Properties
Bound Properties
Constrained Properties
Indexed Properties
Manipulating Events in the BeanBox
The BeanInfo Interface
Bean Customization
Bean Persistence
Using the BeanContext API
Overview of the BeanContext API
Bean Context #1: Containment Only
Bean Context #2: Containment and Services
AWT Containers and the BeanContextProxy Interface
New JavaBeans Features

Trail: JDBC(TM) Database Access

JDBC Basics
Getting Started
Setting Up a Database
Establishing a Connection
Setting Up Tables
Retrieving Values from Result Sets
Updating Tables
Milestone: The Basics of JDBC
Using Prepared Statements
Using Joins
Using Transactions
Stored Procedures
SQL Statements for Creating a Stored Procedure
Creating Complete JDBC Applications
Running the Sample Applications
Creating an Applet from an Application
New Features in the JDBC 2.0 API
Getting Set Up to Use the JDBC 2.0 API
Moving the Cursor in Scrollable Result Sets
Making Updates to Updatable Result Sets
Updating a Result Set Programmatically
Inserting and Deleting Rows Programmatically
Code Sample for Inserting a Row
Deleting a Row
Making Batch Updates
Using SQL3 Datatypes
Standard Extension Features

Trail: RMI

An Overview of RMI Applications
Writing an RMI Server
    Designing a Remote Interface
    Implementing a Remote Interface
Creating a Client Program
Compiling and Running the Example
    Compiling the Example Programs
    Running the Example Programs

Trail: IDL

Introducing Java IDL
What is Java IDL?
The CORBA Architecture
The Java IDL Development Process
The Hello Client-Server Example
Writing the IDL Interface
Developing a Client Application
Developing the Hello World Server
Compiling and Running the Hello World Application
Using Stringified Object References
Summary

Trail: Servlets

Overview of Servlets
Architecture of the Servlet Package
A Simple Servlet
The Example Servlets
Interacting with Clients
Requests and Responses
Handling GET and POST Requests
    Threading Issues
Providing a Servlet Description
The Servlet Life Cycle
Initializing a Servlet
Destroying a Servlet
    Handling Service Threads at Servlet Termination
Saving Client State
Session Tracking
Using Cookies
Servlet Communication
Using Other Server Resources (JSDK 2.1)
Sharing Resources Among Servlets (JSDK 2.1)
Calling Servlets From Servlets (JSDK 2.0)
The servletrunner Utility
Servlet Properties
Starting the Server (JSDK2.1)
Starting servletrunner (JSDK2.0)
Running Servlets
Calling Servlets From a Browser
Calling Servlets From an HTML Page

Trail: Security in Java 2 SDK 1.2

Security Features Overview
Quick Tour of Controlling Applets
Observe Applet Restrictions
Set up a Policy File to Grant the Required Permission
    Start Policy Tool
    Grant the Required Permission
    Save the Policy File
See the Policy File Effects
Quick Tour of Controlling Applications
Observe Application Freedom
See How to Restrict Applications
Set up the Policy File to Grant the Required Permissions
    Open the Policy File
    Grant the Required Permissions
    Save the Policy File
See the Policy File Effects
API and Tools Use for Secure Code and File Exchanges
Signing Code and Granting It Permissions
Steps for the Code Signer
    Download and Try the Sample Application
    Create a JAR File Containing the Class File
    Generate Keys
    Sign the JAR File
    Export the Public Key Certificate
Steps for the Code Receiver
    Observe the Restricted Application
    Import the Certificate as a Trusted Certificate
    Set Up a Policy File to Grant the Required Permission
        Start Policy Tool
        Specify the Keystore
        Add a Policy Entry with a SignedBy Alias
        Save the Policy File
    See the Policy File Effects
Exchanging Files
Steps for the Contract Sender
    Create a JAR File Containing the Contract
    Generate Keys
    Sign the JAR File
    Export the Public Key Certificate
Steps for the Contract Receiver
    Import the Certificate as a Trusted Certificate
    Verify the JAR File Signature
Generating and Verifying Signatures
Generating a Digital Signature
    Prepare Initial Program Structure
    Generate Public and Private Keys
    Sign the Data
    Save the Signature and the Public Key in Files
    Compile and Run the Program
Verifying a Digital Signature
    Prepare Initial Program Structure
    Input and Convert the Encoded Public Key Bytes
    Input the Signature Bytes
    Verify the Signature
    Compile and Run the Program
Weaknesses and Alternatives
Implementing Your Own Permission
TerrysGame
The HighScore Class
The HighScorePermission Class
A Sample Policy File
Putting It All Together
    Steps for the HighScore Developer (Chris)
    Steps for the TerrysGame Developer (Terry)
    Steps for a User Running TerrysGame (Kim)
Summaries
Glossary
API Summary
    What Does the JDK Security API Provide?
    API Classes and Interfaces
Tools Summary
Security-related Files Summary

Trail: JAR Files

Using JAR Files: The Basics
Creating a JAR File
Viewing the Contents of a JAR File
Extracting the Contents of a JAR File
Modifying a Manifest File
Updating a JAR File
Running JAR-Packaged Software
Understanding the Manifest
Signing and Verifying JAR Files
Understanding Signing and Verification
Signing JAR Files
Verifying Signed JAR Files
Using JAR-related APIs Introduced in 1.2
The JarClassLoader Class
The JarRunner Class

Trail: The Extension Mechanism

Creating and Using Extensions
Installed Extensions
Download Extensions
Understanding Extension Class Loading
Making Extensions Secure
Setting Privileges for Extensions
Sealing Packages in Extensions

Trail: Java Native Interface

Overview of the JNI
Writing a Java Program with Native Methods
Step 1: Write the Java Code
Step 2: Compile the Java Code
Step 3: Create the .h File
Step 4: Write the Native Method Implementation
Step 5: Create a Shared Library
Step 6: Run the Program
Integrating Java and Native Programs
Declaring Native Methods
Mapping Between Java and Native Types
Interacting with Java from the Native Side
Accessing Java Strings in Native Methods
Working With Java Arrays in Native Methods
Calling Java Methods
Accessing Java Member Variables
Handling Java Errors from Native Methods
Local and Global References
Threads and Native Methods
JNI Programming in C++
Invoking the Java Virtual Machine
Invoking the Java Virtual Machine
Summary of the JNI

Trail: The Reflection API

Examining Classes
Retrieving Class Objects
Getting the Class Name
Discovering Class Modifiers
Finding Superclasses
Identifying the Interfaces Implemented by a Class
Examining Interfaces
Identifying Class Fields
Discovering Class Constructors
Obtaining Method Information
Manipulating Objects
Creating Objects
    Using No-Argument Constructors
    Using Constructors that Have Arguments
Getting Field Values
Setting Field Values
Invoking Methods
Working with Arrays
Identifying Arrays
Retrieving Component Types
Creating Arrays
Getting and Setting Element Values
Summary of Classes

Trail: Putting It All Together

BINGO!
Traditional BINGO
A Brief Description of the BINGO Programs
Let's Play!
The Code
    The Primary Classes
        The Classes in the bingo.game Package
        The Classes in the bingo.player Package
        The Classes in the bingo.shared Package
What's Interesting?
    Design Decisions
    Using the JFC to Implement the UI's
    Synchronizing and Coordinating Threads
        Using Synchronized Code Segments
        Synchronizing Threads in the Player
        Coordinating Threads in the Game
    Communication Between the Game and the Player
        Broadcasting Game Information
        Handling Player Requests
    Signing and Verifying the BINGO Cards
    Writing a Custom EventQueue and Custom Events
    Managing Program Settings in the Player
    Other Interesting Tidbits
Exercises for the Reader

Trail: Drag and Drop

A Drag and Drop Example by Sheetal Gupta

Trail: Security in JDK 1.1

Java Security API Overview
Using the Security API to Generate Public and Private Keys
Step 1: Prepare Initial Program Structure
Step 2: Generate Public and Private Keys
Step 3: Sign the Data
Step 4: Verify the Signature
Step 5: Compile the Program
Step 6: Run the Program