Home Page Icon
Home Page
Table of Contents for
Learning Java
Close
Learning Java
by Patrick Niemeyer, Jonathan Knudsen
Learning Java
Learning Java
Preface
New Developments
Audience
Using This Book
Getting Wired
Conventions Used in This Book
How to Contact Us
Acknowledgments
1. Yet Another Language?
Enter Java
Java’s Origins
Future Buzz?
A Virtual Machine
Java Compared with Other Languages
Safety of Design
Syntactic Sweet ‘n’ Low
Type Safety and Method Binding
Incremental Development
Dynamic Memory Management
Error Handling
Multithreading
Scalability
Safety of Implementation
The Verifier
Class Loaders
Security Managers
Application and User-Level Security
Signing Classes
Java and the World Wide Web
Applets
New Kinds of Media
New Software Development Models
Java as a General Application Language
A Java Road Map
The Past: Java 1.0 and Java 1.1
The Present: Java 2
The Future
Availability
2. A First Application
HelloJava1
Classes
The main( ) Method
Classes and Objects
Variables and Class Types
Inheritance
The JComponent Class
Relationships and Finger Pointing
Packages
The paintComponent( ) Method
HelloJava2: The Sequel
The import Statement
Instance Variables
Constructors
Events
The repaint( ) Method
Interfaces
HelloJava3: The Button Strikes!
Method Overloading
Garbage Collection
Components
Containers
Layout
Subclassing and Subtypes
More Events and Interfaces
Color Commentary
Static Members
Arrays
Using Color Methods
HelloJava4: Netscape’s Revenge
Threads
The Thread Class
The Runnable Interface
Starting the Thread
Running Code in the Thread
Exceptions
A Word About Synchronization
3. Tools of the Trade
The Java Interpreter
Policy Files
The Default Security Manager
The policytool Utility
Using a Policy File with the Default Security Manager
The Class Path
The Java Compiler
Java Archive (JAR) Files
File Compression
The jar Utility
JAR manifests
4. The Java Language
Text Encoding
Comments
Javadoc Comments
Types
Primitive Types
Floating-point precision
Variable declaration and initialization
Integer literals
Floating-point literals
Character literals
Reference Types
A Word About Strings
Statements and Expressions
Statements
Unreachable statements
Expressions
Operators
Assignment
The null value
Variable access
Method invocation
Object creation
The instanceof operator
Exceptions
Exceptions and Error Classes
Exception Handling
Bubbling Up
Checked and Unchecked Exceptions
Throwing Exceptions
Re-throwing exceptions
Try Creep
The finally Clause
Performance Issues
Arrays
Array Types
Array Creation and Initialization
Using Arrays
Anonymous Arrays
Multidimensional Arrays
Inside Arrays
5. Objects in Java
Classes
Accessing Fields and Methods
Static Members
Methods
Local Variables
Shadowing
The “this” reference
Static Methods
Initializing Local Variables
Argument Passing and References
Method Overloading
Object Creation
Constructors
Working with Overloaded Constructors
Static and Nonstatic Code Blocks
Object Destruction
Garbage Collection
Finalization
6. Relationships Among Classes
Subclassing and Inheritance
Shadowed Variables
Overriding Methods
Overridden methods and dynamic binding
Static method binding
Dynamic method selection and performance
Compiler optimizations
Method selection revisited
Exceptions and overridden methods
Special References: this and super
Casting
Using Superclass Constructors
Full Disclosure: Constructors and Initialization
Abstract Methods and Classes
Interfaces
Interfaces as Callbacks
Interface Variables
Empty interfaces
Subinterfaces
Packages and Compilation Units
Compilation Units
Package Names
Class Visibility
Importing Classes
The Unnamed Package
Visibility of Variables and Methods
Basic Access Modifiers
Subclasses and Visibility
Interfaces and Visibility
Arrays and the Class Hierarchy
Inner Classes
Inner Classes Within Methods
Limitations on inner classes
Static inner classes
Anonymous inner classes
Scoping of the “this” reference
How do inner classes really work?
Security implications
7. Working with Objects and Classes
The Object Class
Equality and Equivalence
Hashcodes
Cloning Objects
The Class Class
Reflection
Security
Accessing Fields
Accessing Methods
Accessing Constructors
What About Arrays?
Dynamic Interface Adapters
What Is Reflection Good for?
The BeanShell application
8. Threads
Introducing Threads
The Thread Class and the Runnable Interface
Creating and starting threads
A natural-born thread
Using an adapter
Controlling Threads
Deprecated methods
The sleep( ) method
The join( ) method
A Thread’s Life
Threads in Applets
Synchronization
Serializing Access to Methods
Accessing instance variables
The wait() and notify( ) Methods
Passing Messages
Scheduling and Priority
Time-Slicing
Priorities
User-Controlled Time-Slicing
Yielding
Native Threads
Thread Groups
Working with the ThreadGroup Class
9. Basic Utility Classes
Strings
String Constructors
Strings from Things
Things from Strings
Comparisons
The Collator class
Searching
Editing
String Method Summary
The java.lang.StringBuffer Class
The java.util.StringTokenizer Class
Math Utilities
The java.lang.Math Class
The java.math Class
Wrappers for Primitive Types
Random Numbers
Dates
Timers
Collections
The Collection Interface
Iterators
Collection Flavors
The Map Interface
Implementations
Hashcodes and key values
Slam Dunking with Collections
Sorting for Free
A Thrilling Example
Thread Safety and Iterators
WeakHashMap: An Interesting Variation
Properties
Default Values
Loading and Storing
System Properties
Observers and Observables
The Security Manager
Internationalization
The java.util.Locale Class
Resource Bundles
The java.text Class
10. Input/Output Facilities
Streams
Terminal I/O
Character Streams
Stream Wrappers
Data streams
Buffered streams
Print streams
Pipes
Strings to Streams and Back
The rot13InputStream Class
Files
The java.io.File Class
File constructors
Path localization
File operations
File Streams
The java.io.RandomAccessFile Class
Applets and Files
Loading Application Resources
Serialization
Data Compression
Compressing Data
Decompressing Data
11. Network Programming with Sockets and RMI
Sockets
Clients and Servers
Clients
Servers
Sockets and security
The DateAtHost Client
The TinyHttpd Server
Do French web servers speak French?
Taming the daemon
Room for improvement
Socket Options
SO_TIMEOUT
TCP_NODELAY
SO_LINGER
TCP_KEEPALIVE
“Half Close”
Proxies and Firewalls
Datagram Sockets
The HeartBeat Applet
The HeartBeat applet code
The Pulse server code
Simple Serialized Object Protocols
A Simple Object-Based Server
Limitations
Remote Method Invocation (RMI)
Remote and Non-Remote Objects
Stubs and skeletons
Remote interfaces
The UnicastRemoteObject class
The RMI registry
An RMI Example
Dynamic class loading
Passing remote object references
RMI Object Activation
RMI and CORBA
12. Programming for the Web
Uniform Resource Locators (URLs)
The URL Class
Stream Data
Getting the Content as an Object
Web Browsers and Handlers
Other Handler Frameworks
Writing Content and Protocol Handlers
Talking to CGI Programs and Servlets
Using the GET Method
Using the POST Method
SSL and Secure Web Communications
Implementing Servlets
Why Servlets?
The Servlet Life Cycle
HTTP (Web) Servlets
The HelloClient Servlet
Content Types
Servlet Parameters
GET, POST, and the “extra path”
Which one to use?
The ShowParameters Servlet
User Session Management
The ShowSession servlet
The ShoppingCart servlet
Cookies
13. Swing
Components
Peers
Why the Move from AWT to Swing?
The Model/View/Controller Framework
Painting
Enabling and Disabling Components
Focus, Please
Other Component Methods
Containers
Layout Managers
Insets
Z-Ordering (Stacking Components)
The revalidate( ) and doLayout( ) Methods
Managing Components
Listening for Components
Windows and Frames
Other Methods for Controlling Frames
Using Content Panes
Events
Event Receivers and Listener Interfaces
Event Sources
Event Delivery
Event Types
The java.awt.event.InputEvent Class
Mouse and Key Modifiers on InputEvents
Event Summary
Adapter Classes
Dummy Adapters
Old-Style and New-Style Event Processing
processEvent( )
Enabling new-style events explicitly
Multithreading in Swing
14. Using Swing Components
Buttons and Labels
Checkboxes and Radio Buttons
Lists and Combo Boxes
Borders
Menus
The PopupMenu Class
The JScrollPane Class
The JSplitPane Class
The JTabbedPane Class
Scrollbars and Sliders
Dialogs
File Selection Dialog
The Color Chooser
15. More Swing Components
Text Components
The TextEntryBox Application
Say the Magic Word
Sharing a Data Model
HTML and RTF for Free
Managing Text Yourself
Trees
Nodes and Models
Save a Tree
Tree Events
A Complete Example
Tables
A First Stab: Freeloading
Round Two: Creating a Table Model
Round Three: A Simple Spreadsheet
Desktops
Pluggable Look-and-Feel
Creating Custom Components
Generating Events
A Dial Component
Model and View Separation
16. Layout Managers
FlowLayout
GridLayout
BorderLayout
BoxLayout
CardLayout
GridBagLayout
The GridBagConstraints Class
Grid Coordinates
The fill Constraint
Spanning Rows and Columns
Weighting
Calculating the weights of rows and columns
Anchoring
Padding and Insets
Relative Positioning
Composite Layouts
Nonstandard Layout Managers
Absolute Positioning
17. Drawing with the 2D API
The Big Picture
The Rendering Pipeline
A Quick Tour of Java 2D
Filling Shapes
Drawing Shape Outlines
Convenience Methods
Drawing Text
Drawing Images
Go Crazy
The Whole Iguana
Filling Shapes
Solid Colors
Color Gradients
Textures
Desktop Colors
Stroking Shape Outlines
Using Fonts
Font Metrics
Displaying Images
The Image Class
Image Observers
Scaling and Size
Using Drawing Techniques
Limited Redrawing
Double Buffering
Offscreen Drawing
Printing
18. Working with Images and Other Media
Implementing an ImageObserver
Using a MediaTracker
Producing Image Data
Drawing Animations
BufferedImage Anatomy
Color Models
Creating an Image
Updating a BufferedImage
Filtering Image Data
How ImageProcessor Works
Converting an Image to a BufferedImage
Using the RescaleOp Class
Using the AffineTransformOp Class
Working with Audio
Working with Movies
19. Java Beans
What’s a Bean?
How Big Is a Bean?
The BeanBox Application
Running the BeanBox application
Properties and Customizers
Events Hookups and Adapters
Bound Properties
Constrained Properties
Building Beans
Creating a Component with Bindable Properties
Design patterns for properties
A (Slightly) More Realistic Example
A Bean for displaying text
A Bean for validating numeric data
An invisible multiplier
Putting them together
Customizing with BeanInfo
Getting Properties information
Getting Events information
Supplying icons
Creating customizers and property editors
Hand-Coding with Beans
Bean Instantiation and Type Management
Working with Serialized Beans
Putting Reflection to Work
Safety Implications
Runtime Event Hookups with Reflection
BeanContext and BeanContextServices
The Java Activation Framework
Enterprise JavaBeans
20. Applets
The JApplet Class
Applet Control
The Applet Security Sandbox
Trusted applets
Getting Applet Resources
Applet parameters
Applet resources
Driving the browser
Inter-applet communication
Applets versus standalone applications
The <APPLET> Tag
Attributes
Parameters
¿Habla Applet?
The Complete <APPLET> Tag
Loading Class Files
Packages
Viewing Applets
Using the Java Plug-in
What Is the Java Plug-in?
Messy Tags
Viewing Plug-in Applets
Using Digital Signatures
Certificates
Certificate authority (CA) certificates
Site certificates
User (signer) certificates
Signed JAR Files: The keytool and jarsigner Utilities
What about Netscape and Internet Explorer?
The TestWrite example
Keystores, Keys, and Certificates
Public and private keys
Certificates
Signing JARs
Where We’ve Been
21. Glossary
A. Content and Protocol Handlers
Writing a Content Handler
Locating Content Handlers
The application/x-tar Handler
The ContentHandler class
The URLConnection
Constructing the object
Using our new handler
Writing a Protocol Handler
Locating Protocol Handlers
URLs, Stream Handlers, and Connections
The crypt Handler
The Encryption class
The URLStreamHandler
The URLConnection
Trying it out
B. BeanShell: Simple Java Scripting
Running BeanShell
Java Statements and Expressions
BeanShell Commands
Scripted Methods and Objects
Learning More . . .
Index
Colophon
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Preface
Learning Java
Jonathan Knudsen
Patrick Niemeyer
Editor
John Posner
Copyright © 2000 O'Reilly Media, Inc.
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset