JDK 1.4 Tutorial
Gregory M. Travis
  • March 2002
  • ISBN 9781930110458
  • 408 pages
This title is out of print and no longer for sale.

JDK 1.4 Tutorial lets experienced developers as well as novices learn JDK 1.4's new features quickly. It provides a clear exposition of the important new topics with plenty of well documented code. All the examples are substantial and solve real-world problems but aren't cluttered with unnecessary details. The new features are covered in a comprehensive and matter-of-fact way without digressions into philosophy or theory. After reading this book, a developer will be able to use Java's new features with confidence and skill.

Table of Contents show full

preface

acknowledgments

about this book

author online

about the cover illustration

1. Basic NIO (New Input/Output)

1.1. Doing I/O with channels and buffers

1.1.1. Getting a channel from a stream

1.1.2. Creating a buffer revision

1.1.3. Reading from a channel

1.1.4. Writing to a channel

1.1.5. Reading and writing together

1.2. Understanding buffers

1.2.1. Creating buffers

1.2.2. get() and put()

1.2.3. Buffer state values

1.2.4. flip() and clear()

1.2.5. slice() and subbuffers

1.2.6. Buffers of other types

1.2.7. Reading and writing other types from a ByteBuffer

1.2.8. Direct buffers

1.2.9. Example: TCP/IP forwarding

1.2.10. Doing I/O with channels and buffers

1.3. The File Locking facility

1.3.1. Types of locks

1.3.2. Using locks

1.3.3. Acquiring locks

1.3.4. Portability issues

1.3.5. Example: a simple database

1.4. Summary

2. Advanced NIO (New Input/Output)

2.1. Reading and writing with MappedByteBuffers

2.1.1. Advantages of MappedByteBuffers

2.1.2. Disadvantages of MappedByteBuffers

2.1.3. Using MappedByteBuffers

2.1.4. Example: checksumming

2.2. Nonblocking I/O

2.2.1. The multithreaded approach

2.2.2. The really bad single-threaded approach

2.2.3. Polling

2.2.4. Example: a polling chat server

2.2.5. Multiplexing with select()

2.3. Encoding and decoding with Charsets

2.3.1. Decoding and encoding

2.3.2. Finding available Charsets

2.3.3. Using encoders and decoders

2.4. Network interfaces

2.4.1. When to use a network interface

2.4.2. Getting a list of NetworkInterfaces

2.4.3. Reporting on NetworkInterfaces

2.4.4. Getting a list of InetAddresses

2.4.5. Getting a NetworkInterface by InetAddress

2.4.6. Getting a NetworkInterface by name

2.4.7. Listening on a particular address

2.5. Summary

3. Java2D

3.1. The Print Service API

3.1.1. Print Service packages

3.1.2. Document flavors

3.1.3. Printer discovery

3.1.4. Printer attributes

3.1.5. The SimpleDoc class

3.1.6. The DocPrintJob interface

3.1.7. Example: printing an image

3.1.8. Example: a custom print dialog box

3.2. Reading and writing images with the Image I/O

3.2.1. The plug-in model

3.2.2. Simple reading

3.2.3. Simple writing

3.2.4. The ImageIO class

3.2.5. Discovering available formats

3.2.6. Example: reading and displaying an image

3.2.7. Example: writing an image

3.2.8. The ImageReader class

3.2.9. The ImageWriter class

3.2.10. Customizing the reading proces

3.2.11. Listeners

3.2.12. Example: generating a graph

3.3. Summary

4. Java Web Start (JAWS)

4.1. Understanding the JAWS execution model

4.1.1. Client, server, and application

4.1.2. The sandbox

4.1.3. Consider the possibilities

4.2. Building and deploying a JAWS application

4.2.1. JAR files

4.2.2. The JNLP file

4.2.3. Configuring the web server

4.3. Using the sandbox: services

4.3.1. Using the sandbox: resources

4.4. Bypassing the sandbox

4.5. Example: a simple drawing program

4.5.1. PicoDraw.java

4.5.2. DrawCanvas.java

4.5.3. TransferableImage.java

4.6. Summary

5. Logging

5.1. Logging overview

5.1.1. Log message format

5.1.2. Logging levels

5.1.3. Logger names and the logger hierarchy

5.1.4. Logging methods

5.1.5. The LogRecord class

5.1.6. Handlers

5.1.7. Filters

5.1.8. Formatters

5.1.9. Logging efficiency

5.1.10. The philosophy of logging

5.2. Configuring the Logging system

5.2.1. Configuring handlers

5.2.2. Configuration values for standard handlers

5.2.3. Configuring loggers

5.2.4. Global handlers

5.3. Using logging in a program

5.4. Writing a custom handler

5.5. Writing a custom formatter

5.6. Summary

6. Assertion facility

6.1. Assertion basics

6.1.1. Why use assertions?

6.1.2. Assertions vs. other error code

6.1.3. Designing by contract

6.2. Working with assertions

6.2.1. Assertion syntax

6.2.2. Compiling with assertions

6.2.3. Controlling assertions from the command line

6.2.4. Controlling assertions programmatically

6.2.5. Removing assertions completely

6.2.6. Determining if assertions are enabled

6.2.7. Catching an assertion failure

6.2.8. Assertions and class initialization

6.3. Assertion examples

6.3.1. Avoiding inconsistent states

6.3.2. Narrowing the range of states

6.3.3. Ensuring consistency between container objects and contained objects

6.3.4. More complicated consistency checks

6.4. Knowing when to use assertions

6.4.1. Rules of use

6.4.2. What to check for

6.4.3. Miscellaneous rules

6.5. Summary

7. Exceptions

7.1. Chained exceptions

7.2. StackTraceElements

7.2.1. What is a stack trace?

7.2.2. Using StackTraceElements

7.2.3. Writing a custom stack trace dumper

7.2.4. Synthesizing a stack trace

7.3. Summary

8. Collections

8.1. Utilities

8.1.1. Rotating list elements

8.1.2. Replacing list elements

8.1.3. Finding sublists within lists

8.1.4. Swapping list elements

8.1.5. Converting enumerations to lists

8.2. LinkedHashMap and LinkedHashSet

8.2.1. Using LinkedHashMap

8.2.2. Using LinkedHashSet

8.2.3. Efficiency of LinkedHashMap and LinkedHashSet

8.2.4. Example: searching a file path

8.3. IdentityHashMap

8.3.1. Object equality

8.3.2. Hashing and equality

8.3.3. Example: using the IdentityHashMap

8.4. The RandomAccess interface

8.5. Summary

9. Regular Expressions

9.1. Overview of regular expressions

9.1.1. Literals

9.1.2. The . wildcard

9.1.3. Quantifiers: * and

9.1.4. Grouping with ()

9.1.5. Character classes

9.1.6. Predefined character classes

9.1.7. Sequencing and alternation

9.1.8. Boundary matchers

9.1.9. Reluctant (non-greedy) matching

9.1.10. Other features

9.2. Pattern and Matcher

9.2.1. Capturing groups

9.2.2. Find and replace

9.2.3. Flags

9.3. Transitioning from Perl to Java

9.3.1. Finding the longest word in a line

9.3.2. Parsing a tab-delimited file

9.3.3. A command-line processor

9.3.4. Parsing and modifying names

9.4. Example: HTML templating system

9.5. Example: a lexical analyzer

9.6. Summary

10. The Preferences API

10.1. What the Preferences API is for

10.1.1. Simple Preferences API example

10.1.2. Appropriate applications of the Preferences API

10.1.3. Design goals of the Preferences API

10.2. Knowing when to use the Preferences API

10.2.1. Comparison with java.util.Properties

10.2.2. Comparison with JNDI

10.3. Understanding the data hierarchy

10.3.1. Tree-like structure

10.3.2. Key/value pairs

10.3.3. System vs. user

10.3.4. Definition of a user

10.3.5. Pathnames

10.3.6. Per-package subtrees

10.4. Using the API

10.4.1. Traversing the data hierarchy

10.4.2. Reading and writing values

10.4.3. Allowable types

10.4.4. Allowable keys

10.4.5. Allowable values

10.4.6. Allowable node names

10.4.7. Default values

10.4.8. Removing values

10.4.9. Iterating through the values in a node

10.4.10. Distinguishing between user and system nodes

10.4.11. Node names and paths

10.4.12. Getting parent and child nodes

10.4.13. Determining the presence of nodes

10.4.14. Removing nodes

10.4.15. Flushing

10.4.16. Syncing

10.4.17. Example: storing GUI configuration

10.5. Change listeners

10.5.1. Preference change listeners

10.5.2. Node change listeners

10.5.3. Example: listening for a GUI change request

10.5.4. Example: changing server ports on the fly

10.6. Stored defaults

10.7. Importing and exporting

10.8. Summary

11. The Java Secure Socket Extension (JSSE)

11.1. Cryptographic terminology

11.2. SSL—the Secure Sockets Layer

11.2.1. Components of the default implementation

11.2.2. SSL handshaking

11.3. Managing keys

11.3.1. Creating keys with keytool

11.3.2. Store keys in a KeyStore

11.3.3. Creating a KeyManagerFactory

11.3.4. Creating a TrustManagerFactory

11.3.5. Creating an SSLContext

11.4. Example: a trivial secure web server

11.4.1. The authentication model

11.4.2. Generating the key

11.4.3. The configuration file

11.4.4. The code

11.5. Example: a secure credit card authorization system

11.5.1. The authentication model

11.5.2. Generating the keys

11.5.3. The code

11.6. Summary

index

About the Technology

Java is a success. It is now used across the programming landscape, from embedded devices to enterprise-class distributed systems. As Java's use increases, the pressure grows for it to expand to meet the diverse needs of the developer communities. The latest edition of Java, JDK 1.4 (or J2SE 1.4), includes new features like a new I/O system, a persistent preferences framework, Java Web Start, and Java regular expressions.

What's inside

  • New Input/Output
    • Non-blocking I/O
    • Channels and buffers
    • Charsets and charset translation
    • TCP/IP connection forwarding
  • Java Web Start
  • Regular Expressions
  • Preferences Library
  • Java Secure Socket Extension
  • Image I/O

About the author

Greg Travis is a consultant and prolific writer based in New York City. He has been a Java programmer since the first day the language was released.