Java Cookbook, 2/e (Paperback)

Ian F Darwin

  • 出版商: O'Reilly
  • 出版日期: 2004-06-24
  • 售價: $1,800
  • 貴賓價: 9.5$1,710
  • 語言: 英文
  • 頁數: 864
  • 裝訂: Paperback
  • ISBN: 0596007019
  • ISBN-13: 9780596007010
  • 相關分類: Java 程式語言
  • 已過版
    無現貨庫存(No stock available)




You have a choice: you can wade your way through lengthy Java tutorials and figure things out by trial and error, or you can pick up Java Cookbook, 2nd Edition and get to the heart of what you need to know when you need to know it.

With the completely revised and thoroughly updated Java Cookbook, 2nd Edition, Java developers like you will learn by example, try out new features, and use sample code to understand how new additions to the language and platform work--and how to put them to work for you.

This comprehensive collection of problems, solutions, and practical examples will satisfy Java developers at all levels of expertise. Whether you're new to Java programming and need something to bridge the gap between theory-laden reference manuals and real-world programs or you're a seasoned Java programmer looking for a new perspective or a different problem-solving context, this book will help you make the most of your Java knowledge.

Packed with hundreds of tried-and-true Java recipes covering all of the major APIs from the 1.4 version of Java, this book also offers significant first-look recipes for the most important features of the new 1.5 version, which is in beta release. You get practical solutions to everyday problems, and each is followed by a detailed, ultimately useful explanation of how and why the technology works.

Java Cookbook, 2nd Edition includes code segments covering many specialized APIs--like those for working with Struts, Ant and other new popular Open Source tools. It also includes expanded Mac OS X Panther coverage and serves as a great launching point for Java developers who want to get started in areas outside of their specialization.

In this major revision, you'll find succinct pieces of code that can be easily incorporated into other programs. Focusing on what's useful or tricky--or what's useful and tricky--Java Cookbook, 2nd Edition is the most practical Java programming book on the market.

Table of Contents:


1. Getting Started: Compiling, Running, and Debugging

      1.1 Compiling and Running Java: JDK

      1.2 Editing and Compiling with a Color-Highlighting Editor

      1.3 Compiling, Running, and Testing with an IDE

      1.4 Using CLASSPATH Effectively

      1.5 Using the com.darwinsys API Classes from This Book

      1.6 Compiling the Source Code Examples from This Book

      1.7 Automating Compilation with Ant

      1.8 Running Applets

      1.9 Dealing with Deprecation Warnings

      1.10 Conditional Debugging Without #ifdef

      1.11 Debugging Printouts

      1.12 Maintaining Program Correctness with Assertions

      1.13 Debugging with JDB

      1.14 Unit Testing: Avoid the Need for Debuggers

      1.15 Getting Readable Tracebacks

      1.16 Finding More Java Source Code

      1.17 Program: Debug

2. Interacting with the Environment

      2.1 Getting Environment Variables

      2.2 System Properties

      2.3 Writing JDK Release-Dependent Code

      2.4 Writing Operating System-Dependent Code

      2.5 Using Extensions or Other Packaged APIs

      2.6 Parsing Command-Line Arguments

3. Strings and Things

      3.1 Taking Strings Apart with Substrings

      3.2 Taking Strings Apart with StringTokenizer



      3.4 Processing a String One Character at a Time

      3.5 Aligning Strings

      3.6 Converting Between Unicode Characters and Strings

      3.7 Reversing a String by Word or by Character

      3.8 Expanding and Compressing Tabs

      3.9 Controlling Case

      3.10 Indenting Text Documents

      3.11 Entering Nonprintable Characters

      3.12 Trimming Blanks from the End of a String

      3.13 Parsing Comma-Separated Data

      3.14 Program: A Simple Text Formatter

      3.15 Program: Soundex Name Comparisons

4. Pattern Matching with Regular Expressions

      4.1 Regular Expression Syntax

      4.2 Using regexes in Java: Test for a Pattern

      4.3 Finding the Matching Text

      4.4 Replacing the Matched Text

      4.5 Printing All Occurrences of a Pattern

      4.6 Printing Lines Containing a Pattern

      4.7 Controlling Case in Regular Expressions

      4.8 Matching "Accented" or Composite Characters

      4.9 Matching Newlines in Text

      4.10 Program: Apache Logfile Parsing

      4.11 Program: Data Mining

      4.12 Program: Full Grep

5. Numbers

      5.1 Checking Whether a String Is a Valid Number

      5.2 Storing a Larger Number in a Smaller Number

      5.3 Converting Numbers to Objects and Vice Versa

      5.4 Taking a Fraction of an Integer Without Using Floating Point

      5.5 Ensuring the Accuracy of Floating-Point Numbers

      5.6 Comparing Floating-Point Numbers

      5.7 Rounding Floating-Point Numbers

      5.8 Formatting Numbers

      5.9 Converting Between Binary, Octal, Decimal, and Hexadecimal

      5.10 Operating on a Series of Integers

      5.11 Working with Roman Numerals

      5.12 Formatting with Correct Plurals

      5.13 Generating Random Numbers

      5.14 Generating Better Random Numbers

      5.15 Calculating Trigonometric Functions

      5.16 Taking Logarithms

      5.17 Multiplying Matrices

      5.18 Using Complex Numbers

      5.19 Handling Very Large Numbers

      5.20 Program: TempConverter

      5.21 Program: Number Palindromes

6. Dates and Times

      6.1 Finding Today's Date

      6.2 Printing Date/Time in a Given Format

      6.3 Representing Dates in Other Epochs

      6.4 Converting YMDHMS to a Calendar or Epoch Seconds

      6.5 Parsing Strings into Dates

      6.6 Converting Epoch Seconds to DMYHMS

      6.7 Adding to or Subtracting from a Date or Calendar

      6.8 Difference Between Two Dates

      6.9 Comparing Dates

      6.10 Day of Week/Month/Year or Week Number

      6.11 Creating a Calendar Page

      6.12 Measuring Elapsed Time

      6.13 Sleeping for a While

      6.14 Program: Reminder Service

7. Structuring Data with Java

      7.1 Using Arrays for Data Structuring

      7.2 Resizing an Array

      7.3 Like an Array, but More Dynamic

      7.4 Using Iterators for Data-Independent Access

      7.5 Structuring Data in a Linked List

      7.6 Mapping with Hashtable and HashMap

      7.7 Storing Strings in Properties and Preferences

      7.8 Sorting a Collection

      7.9 Avoiding the Urge to Sort

      7.10 Eschewing Duplication

      7.11 Finding an Object in a Collection

      7.12 Converting a Collection to an Array

      7.13 Rolling Your Own Iterator

      7.14 Stack

      7.15 Multidimensional Structures

      7.16 Finally, Collections

      7.17 Program: Timing Comparisons

8. Data Structuring with Generics, foreach, and Enumerations (JDK 1.5)

      8.1 Using Generic Collections

      8.2 Using "foreach" Loops

      8.3 Avoid Casting by Using Generics

      8.4 Let Java Convert with AutoBoxing and AutoUnboxing

      8.5 Using Typesafe Enumerations

      8.6 Program: MediaInvoicer

9. Object-Oriented Techniques

      9.1 Printing Objects: Formatting with toString(  )

      9.2 Overriding the Equals Method

      9.3 Overriding the hashCode Method

      9.4 The Clone Method

      9.5 The Finalize Method

      9.6 Using Inner Classes

      9.7 Providing Callbacks via Interfaces

      9.8 Polymorphism/Abstract Methods

      9.9 Passing Values

      9.10 Enforcing the Singleton Pattern

      9.11 Roll Your Own Exceptions

      9.12 Program: Plotter

10. Input and Output

      10.1 Reading Standard Input

      10.2 Writing Standard Output

      10.3 Printing with the 1.5 Formatter

      10.4 Scanning a File with StreamTokenizer

      10.5 Scanning Input with the 1.5 Scanner Class

      10.6 Opening a File by Name

      10.7 Copying a File

      10.8 Reading a File into a String

      10.9 Reassigning the Standard Streams

      10.10 Duplicating a Stream as It Is Written

      10.11 Reading/Writing a Different Character Set

      10.12 Those Pesky End-of-Line Characters

      10.13 Beware Platform-Dependent File Code

      10.14 Reading "Continued" Lines

      10.15 Binary Data

      10.16 Seeking

      10.17 Writing Data Streams from C

      10.18 Saving and Restoring Java Objects

      10.19 Preventing ClassCastExceptions with SerialVersionUID

      10.20 Reading and Writing JAR or Zip Archives

      10.21 Reading and Writing Compressed Files

      10.22 Program: Text to PostScript

11. Directory and Filesystem Operations

      11.1 Getting File Information

      11.2 Creating a File

      11.3 Renaming a File

      11.4 Deleting a File

      11.5 Creating a Transient File

      11.6 Changing File Attributes

      11.7 Listing a Directory

      11.8 Getting the Directory Roots

      11.9 Creating New Directories

      11.10 Program: Find

12. Programming External Devices: Serial and Parallel Ports

      12.1 Choosing a Port

      12.2 Opening a Serial Port

      12.3 Opening a Parallel Port

      12.4 Resolving Port Conflicts

      12.5 Reading and Writing: Lock-Step

      12.6 Reading and Writing: Event-Driven

      12.7 Reading and Writing: Threads

      12.8 Program: Penman Plotter

13. Graphics and Sound

      13.1 Painting with a Graphics Object

      13.2 Testing Graphical Components

      13.3 Drawing Text

      13.4 Drawing Centered Text in a Component

      13.5 Drawing a Drop Shadow

      13.6 Drawing Text with 2D

      13.7 Drawing Text with an Application Font

      13.8 Drawing an Image

      13.9 Playing a Sound File

      13.10 Playing a Video Clip

      13.11 Printing in Java

      13.12 Program: PlotterAWT

      13.13 Program: Grapher

14. Graphical User Interfaces

      14.1 Displaying GUI Components

      14.2 Designing a Window Layout

      14.3 A Tabbed View of Life

      14.4 Action Handling: Making Buttons Work

      14.5 Action Handling Using Anonymous Inner Classes

      14.6 Terminating a Program with "Window Close"

      14.7 Dialogs: When Later Just Won't Do

      14.8 Catching and Formatting GUI Exceptions

      14.9 Getting Program Output into a Window

      14.10 Choosing a Value with JSpinner

      14.11 Choosing a File with JFileChooser

      14.12 Choosing a Color

      14.13 Formatting JComponents with HTML

      14.14 Centering a Main Window

      14.15 Changing a Swing Program's Look and Feel

      14.16 Enhancing Your GUI for Mac OS X

      14.17 Program: Custom Font Chooser

      14.18 Program: Custom Layout Manager

15. Internationalization and Localization

      15.1 Creating a Button with I18N Resources

      15.2 Listing Available Locales

      15.3 Creating a Menu with I18N Resources

      15.4 Writing Internationalization Convenience Routines

      15.5 Creating a Dialog with I18N Resources

      15.6 Creating a Resource Bundle

      15.7 Extracting Strings from Your Code

      15.8 Using a Particular Locale

      15.9 Setting the Default Locale

      15.10 Formatting Messages

      15.11 Program: MenuIntl

      15.12 Program: BusCard

16. Network Clients

      16.1 Contacting a Server

      16.2 Finding and Reporting Network Addresses

      16.3 Handling Network Errors

      16.4 Reading and Writing Textual Data

      16.5 Reading and Writing Binary Data

      16.6 Reading and Writing Serialized Data

      16.7 UDP Datagrams

      16.8 Program: TFTP UDP Client

      16.9 Program: Telnet Client

      16.10 Program: Chat Client

17. Server-Side Java: Sockets

      17.1 Opening a Server for Business

      17.2 Returning a Response (String or Binary)

      17.3 Returning Object Information

      17.4 Handling Multiple Clients

      17.5 Serving the HTTP Protocol

      17.6 Securing a Web Server with SSL and JSSE

      17.7 Network Logging

      17.8 Network Logging with log4j

      17.9 Network Logging with JDK 1.4

      17.10 Finding Network Interfaces

      17.11 Program: A Java Chat Server

18. Network Clients II: Applets and Web Clients

      18.1 Embedding Java in a Web Page

      18.2 Applet Techniques

      18.3 Contacting a Server on the Applet Host

      18.4 Making an Applet Show a Document

      18.5 Making an Applet Run JavaScript

      18.6 Making an Applet Run a CGI Script

      18.7 Reading the Contents of a URL

      18.8 URI, URL, or URN?

      18.9 Extracting HTML from a URL

      18.10 Extracting URLs from a File

      18.11 Converting a Filename to a URL

      18.12 Program: MkIndex

      18.13 Program: LinkChecker

19. Java and Electronic Mail

      19.1 Sending Email: Browser Version

      19.2 Sending Email: For Real

      19.3 Mail-Enabling a Server Program

      19.4 Sending MIME Mail

      19.5 Providing Mail Settings

      19.6 Sending Mail Without Using JavaMail

      19.7 Reading Email

      19.8 Program: MailReaderBean

      19.9 Program: MailClient

20. Database Access

      20.1 Easy Database Access with JDO

      20.2 Text-File Databases

      20.3 DBM Databases

      20.4 JDBC Setup and Connection

      20.5 Connecting to a JDBC Database

      20.6 Sending a JDBC Query and Getting Results

      20.7 Using JDBC Prepared Statements

      20.8 Using Stored Procedures with JDBC

      20.9 Changing Data Using a ResultSet

      20.10 Storing Results in a RowSet

      20.11 Changing Data Using SQL

      20.12 Finding JDBC Metadata

      20.13 Program: SQLRunner

21. XML

      21.1 Generating XML from Objects

      21.2 Transforming XML with XSLT

      21.3 Parsing XML with SAX

      21.4 Parsing XML with DOM

      21.5 Verifying Structure with a DTD

      21.6 Generating Your Own XML with DOM

      21.7 Program: xml2mif

22. Distributed Java: RMI

      22.1 Defining the RMI Contract

      22.2 Creating an RMI Client

      22.3 Creating an RMI Server

      22.4 Deploying RMI Across a Network

      22.5 Program: RMI Callbacks

      22.6 Program: NetWatch

23. Packages and Packaging

      23.1 Creating a Package

      23.2 Documenting Classes with Javadoc

      23.3 Beyond JavaDoc: Annotations/Metadata (JDK 1.5) and XDoclet

      23.4 Archiving with jar

      23.5 Running an Applet from a JAR

      23.6 Running an Applet with a Modern JDK

      23.7 Running a Main Program from a JAR

      23.8 Preparing a Class as a JavaBean

      23.9 Pickling Your Bean into a JAR

      23.10 Packaging a Servlet into a WAR File

      23.11 "Write Once, Install Anywhere"

      23.12 "Write Once, Install on Mac OS X"

      23.13 Java Web Start

      23.14 Signing Your JAR File

24. Threaded Java

      24.1 Running Code in a Different Thread

      24.2 Displaying a Moving Image with Animation

      24.3 Stopping a Thread

      24.4 Rendezvous and Timeouts

      24.5 Synchronizing Threads with the synchronized Keyword

      24.6 Simplifying Synchronization with 1.5 Locks

      24.7 Synchronizing Threads with wait( ) and notifyAll( )

      24.8 Simplifying Producer-Consumer with the 1.5 Queue Interface

      24.9 Background Saving in an Editor

      24.10 Program: Threaded Network Server

      24.11 Simplifying Servers Using the Concurrency Utilities (JDK 1.5)

25. Introspection, or "A Class Named Class"

      25.1 Getting a Class Descriptor

      25.2 Finding and Using Methods and Fields

      25.3 Loading and Instantiating a Class Dynamically

      25.4 Constructing a Class from Scratch

      25.5 Performance Timing

      25.6 Printing Class Information

      25.7 Program: CrossRef

      25.8 Program: AppletViewer

26. Using Java with Other Languages

      26.1 Running a Program

      26.2 Running a Program and Capturing Its Output

      26.3 Mixing Java and Scripts with BSF

      26.4 Marrying Java and Perl

      26.5 Blending in Native Code (C/C++)

      26.6 Calling Java from Native Code

      26.7 Program: DBM