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
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 Nuts and Bolts of the Java Language
Run the Application
Variables and Data Types
Operators
Expressions
Control Flow Statements
Arrays and Strings
Other Features of the Character-Counting Application
The main() Method
Introducing Exceptions
The Standard Input and Output Streams
Objects, Classes, and Interfaces
The Life Cycle of an Object
Creating Objects
Using Objects
Cleaning Up Unused Objects
Creating Classes
The Class Declaration
The Class Body
Declaring Member Variables
Implementing Methods
The Method Declaration
Passing Information into a Method
The Method Body
Instance and Class Members
Controlling Access to Members of a Class
Life Cycle Methods
Constructors
Writing a finalize() Method
Subclasses, Superclasses, and Inheritance
Creating Subclasses
Overriding Methods
Writing Final Classes and Methods
Writing Abstract Classes and Methods
The Object Class
Creating and Using Interfaces
What Are Interfaces?
Defining an Interface
Implementing an Interface
Using an Interface as a Type
Creating and Using Packages
Roll Your Own Packages
Using the Classes and Interfaces from a Package
The Java Packages
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
Java Strings are First-Class Objects
Setting Program Attributes
Setting Up and Using Properties
Command Line Arguments
Conventions
Parsing Command Line Arguments
Using System Resources
Using the System Class
The Standard I/O Streams
System Properties
Forcing Finalization and Garbage Collection
Miscellaneous System Methods
Using System-Dependent Resources
Handling Errors using 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
Threads of Control
What Is a Thread?
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 Input and Output Streams
Using Input and Output Streams
Using Streams to Implement Pipes
Using Streams to Read and Write Files
Using Streams to Read and Write Memory Locations
Using Streams to Concatenate Files
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 Random Access Files
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
Examples
What Applets Can and Can't Do
Adding an Applet to an HTML Page
Summary
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 on the Same Page
Communicating with the Browser
Working with a Server-Side Application
A Simple Network Client Applet
Using a Server to Work Around Security Restrictions
Understanding Applet Capabilities and Restrictions
Security Restrictions
Applet Capabilities
Finishing an Applet
Before You Ship that Applet
The Perfectly Finished 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
How to Use an Image Filter
How to Write an Image Filter
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
Overview of Networking
Networking Basics
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
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
Deciding What SecurityManager Methods to Override
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 Native Method Implementation
Step 6: Create a Shared Library
Step 7: Run the Program
Implementing Native Methods
The Character Replacement Program
The Method Signature and the Function Signature
Passing Data into a Native Method
Returning a Value from a Native Method
Using a Java Object in a Native Method
Working with Strings
Native Methods and Thread Synchronization
Throwing Exceptions from Within a Native Method
Using C++ in Native Method Implementations