1. Trang chủ
  2. » Công Nghệ Thông Tin

JDK 1.4 Tutorial doc

408 639 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • contents

  • preface

  • acknowledgments

  • about this book

  • author online

  • about the cover illustration

  • 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

  • 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

  • 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 API

      • 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 process

      • 3.2.11 Listeners

      • 3.2.12 Example: generating a graph

    • 3.3 Summary

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

Nội dung

JDK 1.4 Tutorial jdk.book Page i Monday, March 11, 2002 3:38 PM jdk.book Page ii Monday, March 11, 2002 3:38 PM JDK 1.4 Tutorial GREG M. TRAVIS MANNING Greenwich (74° w. long.) jdk.book Page iii Monday, March 11, 2002 3:38 PM For electronic information and ordering of this and other Manning books, go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 209 Bruce Park Avenue Fax: (203) 661-9018 Greenwich, CT 06830 email: orders@manning.com ©2002 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books they publish printed on acid-free paper, and we exert our best efforts to that end. Library of Congress Cataloging-in-Publication Data Travis, Greg Book Title /Bill J. Author. p. cm. Includes bibliographical references and index. ISBN ?-??????-??-? (alk. paper) 1. Java (Computer program language). 2. Title. ????????????? 1998 ?????????—???? ??-????? CIP Manning Publications Co. Copyeditor: Andy Carroll 209 Bruce Park Avenue Typesetter: Tony Roberts Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-930110-66-9 Printed in the United States of America 12345678910– VHG – 05 04 03 02 jdk.book Page iv Monday, March 11, 2002 3:38 PM To Susan jdk.book Page v Monday, March 11, 2002 3:38 PM jdk.book Page vi Monday, March 11, 2002 3:38 PM vii preface xv acknowledgments xvii about this book xix author online xxvii about the cover illustration xxix 1 Basic NIO (New Input/Output) 1 1.1 Doing I/O with channels and buffers 2 Getting a channel from a stream 3 ■ Creating a buffer revision 4 ■ Reading from a channel 4 ■ Writing to a channel 5 ■ Reading and writing together 6 1.2 Understanding buffers 7 Creating buffers 7 ■ get() and put() 7 ■ Buffer state values 9 flip() and clear() 10 ■ slice() and subbuffers 12 ■ Buffers of other types 13 ■ Reading and writing other types from a ByteBuffer 14 ■ Direct buffers 16 ■ Example: TCP/IP forwarding 17 ■ Doing I/O with channels and buffers 27 1.3 The File Locking facility 28 Types of locks 28 ■ Using locks 29 ■ Acquiring locks 30 Portability issues 31 ■ Example: a simple database 32 1.4 Summary 36 contents jdk.book Page vii Monday, March 11, 2002 3:38 PM viii CONTENTS 2 Advanced NIO (New Input/Output) 37 2.1 Reading and writing with MappedByteBuffers 38 Advantages of MappedByteBuffers 38 ■ Disadvantages of MappedByteBuffers 40 ■ Using MappedByteBuffers 40 Example: checksumming 41 2.2 Nonblocking I/O 42 The multithreaded approach 43 ■ The really bad single- threaded approach 44 ■ Polling 44 ■ Example: a polling chat server 46 ■ Multiplexing with select() 49 2.3 Encoding and decoding with Charsets 58 Decoding and encoding 59 ■ Finding available Charsets 59 Using encoders and decoders 61 2.4 Network interfaces 63 When to use a network interface 64 ■ Getting a list of NetworkInterfaces 64 ■ Reporting on NetworkInterfaces 64 Getting a list of InetAddresses 66 ■ Getting a NetworkInterface by InetAddress 66 ■ Getting a NetworkInterface by name 67 ■ Listening on a particular address 67 2.5 Summary 73 3 Java2D 75 3.1 The Print Service API 76 Print Service packages 76 ■ Document flavors 77 ■ Printer discovery 77 ■ Printer attributes 79 ■ The SimpleDoc class 80 The DocPrintJob interface 81 ■ Example: printing an image 81 ■ Example: a custom print dialog box 83 3.2 Reading and writing images with the Image I/O API 88 The plug-in model 89 ■ Simple reading 89 ■ Simple writing 90 ■ The ImageIO class 90 ■ Discovering available formats 90 ■ Example: reading and displaying an image 92 Example: writing an image 92 ■ The ImageReader class 93 The ImageWriter class 95 ■ Customizing the reading process 97 ■ Listeners 99 ■ Example: generating a graph 102 jdk.book Page viii Monday, March 11, 2002 3:38 PM CONTENTS ix 3.3 Summary 105 4 Java Web Start (JAWS) 107 4.1 Understanding the JAWS execution model 108 Client, server, and application 109 ■ The sandbox 110 Consider the possibilities 110 4.2 Building and deploying a JAWS application 111 JAR files 111 ■ The JNLP file 111 Configuring the web server 113 4.3 Using the sandbox: services 113 Using the sandbox: resources 114 4.4 Bypassing the sandbox 115 4.5 Example: a simple drawing program 117 PicoDraw.java 118 ■ DrawCanvas.java 131 TransferableImage.java 135 4.6 Summary 136 5 Logging 137 5.1 Logging overview 138 Log message format 139 ■ Logging levels 139 ■ Logger names and the logger hierarchy 140 ■ Logging methods 141 The LogRecord class 141 ■ Handlers 142 ■ Filters 143 Formatters 143 ■ Logging efficiency 144 The philosophy of logging 144 5.2 Configuring the Logging system 145 Configuring handlers 145 ■ Configuration values for standard handlers 146 ■ Configuring loggers 148 Global handlers 149 5.3 Using logging in a program 149 5.4 Writing a custom handler 155 5.5 Writing a custom formatter 165 5.6 Summary 168 jdk.book Page ix Monday, March 11, 2002 3:38 PM x CONTENTS 6 Assertion facility 171 6.1 Assertion basics 172 Why use assertions? 172 ■ Assertions vs. other error code 173 Designing by contract 174 6.2 Working with assertions 174 Assertion syntax 175 ■ Compiling with assertions 177 Controlling assertions from the command line 178 Controlling assertions programmatically 181 ■ Removing assertions completely 182 ■ Determining if assertions are enabled 183 ■ Catching an assertion failure 184 Assertions and class initialization 185 6.3 Assertion examples 187 Avoiding inconsistent states 187 ■ Narrowing the range of states 189 ■ Ensuring consistency between container objects and contained objects 189 ■ More complicated consistency checks 192 6.4 Knowing when to use assertions 193 Rules of use 193 ■ What to check for 197 Miscellaneous rules 202 6.5 Summary 204 7 Exceptions 205 7.1 Chained exceptions 206 7.2 StackTraceElements 208 What is a stack trace? 208 ■ Using StackTraceElements 210 Writing a custom stack trace dumper 210 Synthesizing a stack trace 215 7.3 Summary 228 jdk.book Page x Monday, March 11, 2002 3:38 PM [...]... (parameterized types) feature was, in the end, not included with JDK 1.4 as originally promised This controversial addition to the language looks like it will be included in JDK 1.5 for sure, and you can download an early-access version of it from Sun However, since it requires a change to the compiler, it can’t really be said to be a part of JDK 1.4 and so is not discussed in this book Who should read this... archives of previous discussions will be accessible from the publisher’s web site as long as the book is in print xxvii jdk. book Page xxviii Monday, March 11, 2002 3:38 PM jdk. book Page xxix Monday, March 11, 2002 3:38 PM about the cover illustration The figure on the cover of JDK 1.4 Tutorial is a woman of late eighteenth century Armenia, attired in an ornate and beautiful dress While the details of... programs are too long to be conveniently entered by hand; the book’s web site, at http://www.manning.com/travis/, has all of the code available for download jdk. book Page xxvii Monday, March 11, 2002 3:38 PM author online When you purchase JDK 1.4 Tutorial, you also get free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions,... programmer who needs to use the new features of JDK 1.4 I’ve tried to include enough introductory material that beginners will also find this book useful; however, this book will not teach you to program—it assumes you already know how This book is intended to guide the reader through the essentials of most of the new packages, libraries, and features in the JDK 1.4 release of the Java programming language... brought back to life by the pictures from this collection jdk. book Page 1 Monday, March 11, 2002 3:38 PM 1 Basic NIO (New Input/Output) This chapter covers I The New I/O system I Doing I/O with channels and buffers I File locking 1 jdk. book Page 2 Monday, March 11, 2002 3:38 PM 2 CHAPTER 1 Basic NIO The New I/O (NIO) API introduced in JDK 1.4 provides a completely new model of low-level I/O Unlike... applications, assertions are crucial to maintaining software throughout its release cycle Chapter 7—Exceptions While we’re on the subject of errors, there are a couple of nice surprises in JDK 1.4 in the area of Exceptions jdk. book Page xxiv Monday, March 11, 2002 3:38 PM xxiv ABOUT THIS BOOK The new StackTraceElement object allows a program to access each stack frame of an exception’s stack trace, giving... Beal, Esq., for her love and patience (and even a bit of proofreading) throughout the writing of this book, and more thanks to Hume Beal for his purring and enthusiasm jdk. book Page xix Monday, March 11, 2002 3:38 PM about this book The JDK 1.4 release of the Java programming language from Sun Microsystems represents a substantial step in Java’s progress Some of the new features are packages that have... Creating an SSLContext 345 I I I 11.4 Example: a trivial secure web server 346 The authentication model 346 Generating the key 347 The configuration file 348 The code 349 I I 11.5 Example: a secure credit card authorization system 359 The authentication model 359 Generating the keys 360 The code 362 I 11.6 index Summary 371 370 jdk. book Page xiv Monday, March 11, 2002 3:38 PM jdk. book Page xv Monday, March... when your projects demand it JDK 1.4 is another step on this path It includes a variety of new features, some of which have been available in prototype form, but all of which are now firmly part of the Java platform These features are not yet available in most browsers, but if you use Java for true application development, you’ll want to learn how to use them right away jdk. book Page xvii Monday, March... available on a computer, as well as the full range of printing options available on each printer It is intended to supersede the java.awt.print package Document classes allow you to create printable objects in a variety of formats and submit those documents to printers that support these formats Listeners allow your application to track the progress of the print job so you can report back to the user . 11 1 ■ The JNLP file 11 1 Configuring the web server 11 3 4. 3 Using the sandbox: services 11 3 Using the sandbox: resources 11 4 4 .4 Bypassing the sandbox 11 5 4. 5. 14 2 ■ Filters 14 3 Formatters 14 3 ■ Logging efficiency 14 4 The philosophy of logging 14 4 5.2 Configuring the Logging system 14 5 Configuring handlers 14 5 ■ Configuration

Ngày đăng: 14/03/2014, 21:20

TỪ KHÓA LIÊN QUAN

w