You are previewing Java Cookbook, 2nd Edition.
O'Reilly logo
Java Cookbook, 2nd Edition

Book Description

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. Java Cookbook, 2nd Edition
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Preface to the Second Edition
    2. Preface to the First Edition
    3. Who This Book Is For
    4. What's in This Book?
    5. Platform Notes
    6. Other Books
      1. Other Java Books
      2. General Programming Books
      3. Design Books
    7. Conventions Used in This Book
      1. Programming Conventions
      2. Typesetting Conventions
    8. Comments and Questions
    9. Getting the Source Code
    10. Acknowledgments
  4. 1. Getting Started: Compiling, Running, and Debugging
    1. Introduction
    2. 1.1. Compiling and Running Java: JDK
      1. Problem
      2. Solution
        1. JDK
        2. Command-line alternatives
        3. Mac OS X
    3. 1.2. Editing and Compiling with a Color-Highlighting Editor
      1. Problem
      2. Solution
      3. Discussion
    4. 1.3. Compiling, Running, and Testing with an IDE
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 1.4. Using CLASSPATH Effectively
      1. Problem
      2. Solution
      3. Discussion
    6. 1.5. Using the com.darwinsys API Classes from This Book
      1. Problem
      2. Solution
      3. Discussion
    7. 1.6. Compiling the Source Code Examples from This Book
      1. Problem
      2. Solution
      3. Discussion
        1. A caveat
    8. 1.7. Automating Compilation with Ant
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 1.8. Running Applets
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 1.9. Dealing with Deprecation Warnings
      1. Problem
      2. Solution
      3. Discussion
    11. 1.10. Conditional Debugging Without #ifdef
      1. Problem
      2. Solution
      3. Discussion
        1. Conditional compilation?
      4. See Also
    12. 1.11. Debugging Printouts
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 1.12. Maintaining Program Correctness with Assertions
      1. Problem
      2. Solution
      3. Discussion
    14. 1.13. Debugging with JDB
      1. Problem
      2. Solution
      3. Discussion
    15. 1.14. Unit Testing: Avoid the Need for Debuggers
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 1.15. Getting Readable Tracebacks
      1. Problem
      2. Solution
      3. Discussion
    17. 1.16. Finding More Java Source Code
      1. Problem
      2. Solution
      3. Discussion
    18. 1.17. Program: Debug
  5. 2. Interacting with the Environment
    1. Introduction
    2. 2.1. Getting Environment Variables
      1. Problem
      2. Solution
      3. Discussion
        1. 1.4 and earlier
        2. Back to the future: 1.5
    3. 2.2. System Properties
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 2.3. Writing JDK Release-Dependent Code
      1. Problem
      2. Solution
      3. Discussion
    5. 2.4. Writing Operating System-Dependent Code
      1. Problem
      2. Solution
      3. Discussion
    6. 2.5. Using Extensions or Other Packaged APIs
      1. Problem
      2. Solution
      3. Discussion
    7. 2.6. Parsing Command-Line Arguments
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  6. 3. Strings and Things
    1. Introduction
    2. 3.1. Taking Strings Apart with Substrings
      1. Problem
      2. Solution
      3. Discussion
    3. 3.2. Taking Strings Apart with StringTokenizer
      1. Problem
      2. Solution
      3. See Also
    4. 3.3. Putting Strings Together with +, StringBuilder (JDK 1.5), and StringBuffer
      1. Problem
      2. Solution
      3. Discussion
    5. 3.4. Processing a String One Character at a Time
      1. Problem
      2. Solution
      3. Discussion
    6. 3.5. Aligning Strings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 3.6. Converting Between Unicode Characters and Strings
      1. Problem
      2. Solution
      3. See Also
    8. 3.7. Reversing a String by Word or by Character
      1. Problem
      2. Solution
      3. Discussion
    9. 3.8. Expanding and Compressing Tabs
      1. Problem
      2. Solution
      3. Discussion
    10. 3.9. Controlling Case
      1. Problem
      2. Solution
      3. See Also
    11. 3.10. Indenting Text Documents
      1. Problem
      2. Solution
    12. 3.11. Entering Nonprintable Characters
      1. Problem
      2. Solution
      3. Discussion
    13. 3.12. Trimming Blanks from the End of a String
      1. Problem
      2. Solution
      3. Discussion
    14. 3.13. Parsing Comma-Separated Data
      1. Problem
      2. Solution
      3. Discussion
    15. 3.14. Program: A Simple Text Formatter
    16. 3.15. Program: Soundex Name Comparisons
  7. 4. Pattern Matching with Regular Expressions
    1. Introduction
      1. See Also
    2. 4.1. Regular Expression Syntax
      1. Problem
      2. Solution
      3. Discussion
    3. 4.2. Using regexes in Java: Test for a Pattern
      1. Problem
      2. Solution
      3. Discussion
    4. 4.3. Finding the Matching Text
      1. Problem
      2. Solution
    5. 4.4. Replacing the Matched Text
    6. 4.5. Printing All Occurrences of a Pattern
      1. Problem
      2. Solution
    7. 4.6. Printing Lines Containing a Pattern
      1. Problem
      2. Solution
      3. Discussion
    8. 4.7. Controlling Case in Regular Expressions
      1. Problem
      2. Solution
    9. 4.8. Matching "Accented" or Composite Characters
      1. Problem
      2. Solution
      3. Discussion
    10. 4.9. Matching Newlines in Text
      1. Problem
      2. Solution
      3. Discussion
    11. 4.10. Program: Apache Logfile Parsing
    12. 4.11. Program: Data Mining
    13. 4.12. Program: Full Grep
  8. 5. Numbers
    1. Introduction
      1. See Also
    2. 5.1. Checking Whether a String Is a Valid Number
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 5.2. Storing a Larger Number in a Smaller Number
      1. Problem
      2. Solution
      3. Discussion
    4. 5.3. Converting Numbers to Objects and Vice Versa
      1. Problem
      2. Solution
      3. Discussion
    5. 5.4. Taking a Fraction of an Integer Without Using Floating Point
      1. Problem
      2. Solution
      3. Discussion
    6. 5.5. Ensuring the Accuracy of Floating-Point Numbers
      1. Problem
      2. Solution
    7. 5.6. Comparing Floating-Point Numbers
      1. Problem
      2. Solution
    8. 5.7. Rounding Floating-Point Numbers
      1. Problem
      2. Solution
    9. 5.8. Formatting Numbers
      1. Problem
      2. Solution
      3. See Also
    10. 5.9. Converting Between Binary, Octal, Decimal, and Hexadecimal
      1. Problem
      2. Solution
      3. Discussion
    11. 5.10. Operating on a Series of Integers
      1. Problem
      2. Solution
      3. Discussion
    12. 5.11. Working with Roman Numerals
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 5.12. Formatting with Correct Plurals
      1. Problem
      2. Solution
    14. 5.13. Generating Random Numbers
      1. Problem
      2. Solution
      3. See Also
    15. 5.14. Generating Better Random Numbers
      1. Problem
      2. Solution
      3. See Also
    16. 5.15. Calculating Trigonometric Functions
      1. Problem
      2. Solution
    17. 5.16. Taking Logarithms
      1. Problem
      2. Solution
      3. Discussion
    18. 5.17. Multiplying Matrices
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 5.18. Using Complex Numbers
      1. Problem
      2. Solution
    20. 5.19. Handling Very Large Numbers
      1. Problem
      2. Solution
      3. Discussion
    21. 5.20. Program: TempConverter
    22. 5.21. Program: Number Palindromes
      1. See Also
  9. 6. Dates and Times
    1. Introduction
    2. 6.1. Finding Today's Date
      1. Problem
      2. Solution
      3. Discussion
    3. 6.2. Printing Date/Time in a Given Format
      1. Problem
      2. Solution
      3. Discussion
    4. 6.3. Representing Dates in Other Epochs
      1. Problem
      2. Solution
      3. Discussion
    5. 6.4. Converting YMDHMS to a Calendar or Epoch Seconds
      1. Problem
      2. Solution
    6. 6.5. Parsing Strings into Dates
      1. Problem
      2. Solution
      3. Discussion
    7. 6.6. Converting Epoch Seconds to DMYHMS
      1. Problem
      2. Solution
      3. Discussion
    8. 6.7. Adding to or Subtracting from a Dateor Calendar
      1. Problem
      2. Solution
      3. Discussion
    9. 6.8. Difference Between Two Dates
      1. Problem
      2. Solution
      3. Discussion
    10. 6.9. Comparing Dates
      1. Problem
      2. Solution
      3. Discussion
    11. 6.10. Day of Week/Month/Year or Week Number
      1. Problem
      2. Solution
      3. Discussion
    12. 6.11. Creating a Calendar Page
      1. Problem
      2. Solution
      3. Discussion
    13. 6.12. Measuring Elapsed Time
      1. Problem
      2. Solution
      3. Discussion
    14. 6.13. Sleeping for a While
      1. Problem
      2. Solution
      3. Discussion
    15. 6.14. Program: Reminder Service
      1. See Also
  10. 7. Structuring Data with Java
    1. Introduction
    2. 7.1. Using Arrays for Data Structuring
      1. Problem
      2. Solution
      3. Discussion
    3. 7.2. Resizing an Array
      1. Problem
      2. Solution
      3. Discussion
    4. 7.3. Like an Array, but More Dynamic
      1. Problem
      2. Solution
      3. Discussion
    5. 7.4. Using Iterators for Data-Independent Access
      1. Problem
      2. Solution
      3. Discussion
    6. 7.5. Structuring Data in a Linked List
      1. Problem
      2. Solution
      3. Discussion
    7. 7.6. Mapping with Hashtable and HashMap
      1. Problem
      2. Solution
      3. Discussion
    8. 7.7. Storing Strings in Properties and Preferences
      1. Problem
      2. Solution
      3. Discussion
        1. Preferences
        2. Properties
        3. Commercial solution for Windows registry access
    9. 7.8. Sorting a Collection
      1. Problem
      2. Solution
      3. Discussion
    10. 7.9. Avoiding the Urge to Sort
      1. Problem
      2. Solution
      3. Discussion
    11. 7.10. Eschewing Duplication
      1. Problem
      2. Solution
      3. Discussion
    12. 7.11. Finding an Object in a Collection
      1. Problem
      2. Solution
      3. Discussion
    13. 7.12. Converting a Collection to an Array
      1. Problem
      2. Solution
      3. Discussion
    14. 7.13. Rolling Your Own Iterator
      1. Problem
      2. Solution
      3. Discussion
    15. 7.14. Stack
      1. Problem
      2. Solution
      3. Discussion
    16. 7.15. Multidimensional Structures
      1. Problem
      2. Solution
      3. Discussion
    17. 7.16. Finally, Collections
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 7.17. Program: Timing Comparisons
  11. 8. Data Structuring with Generics, foreach, and Enumerations (JDK 1.5)
    1. Introduction
      1. See Also
    2. 8.1. Using Generic Collections
      1. Problem
      2. Solution
      3. Discussion
    3. 8.2. Using "foreach" Loops
      1. Problem
      2. Solution
      3. Discussion
    4. 8.3. Avoid Casting by Using Generics
      1. Problem
      2. Solution
      3. Discussion
    5. 8.4. Let Java Convert with AutoBoxing and AutoUnboxing
      1. Problem
      2. Solution
      3. Discussion
    6. 8.5. Using Typesafe Enumerations
      1. Problem
      2. Solution
      3. Discussion
    7. 8.6. Program: MediaInvoicer
  12. 9. Object-Oriented Techniques
    1. Introduction
      1. Advice, or Mantras
        1. Use the API
        2. Generalize
        3. Read and write Javadoc
        4. Use subclassing and delegation
        5. Use design patterns
    2. 9.1. Printing Objects: Formatting with toString( )
      1. Problem
      2. Solution
      3. Discussion
    3. 9.2. Overriding the Equals Method
      1. Problem
      2. Solution
      3. Discussion
    4. 9.3. Overriding the hashCode Method
      1. Problem
      2. Discussion
    5. 9.4. The Clone Method
      1. Problem
      2. Solution
      3. Discussion
        1. Using cloning
        2. Difficulty in the standard API
    6. 9.5. The Finalize Method
      1. Problem
      2. Solution
      3. Discussion
    7. 9.6. Using Inner Classes
      1. Problem
      2. Solution
      3. Discussion
    8. 9.7. Providing Callbacks via Interfaces
      1. Problem
      2. Solution
      3. Discussion
    9. 9.8. Polymorphism/Abstract Methods
      1. Problem
      2. Solution
      3. Discussion
    10. 9.9. Passing Values
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 9.10. Enforcing the Singleton Pattern
      1. Problem
      2. Solution
      3. Discussion
      4. 9.10.4. Variation
      5. See Also
    12. 9.11. Roll Your Own Exceptions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 9.12. Program: Plotter
  13. 10. Input and Output
    1. Introduction
      1. Streams and Readers/Writers
      2. See Also
    2. 10.1. Reading Standard Input
      1. Problem
      2. Solution
      3. Discussion
    3. 10.2. Writing Standard Output
      1. Problem
      2. Solution
      3. Discussion
    4. 10.3. Printing with the 1.5 Formatter
      1. Problem
      2. Solution
      3. Discussion
    5. 10.4. Scanning a File with StreamTokenizer
      1. Problem
      2. Solution
      3. Discussion
    6. 10.5. Scanning Input with the 1.5 Scanner Class
      1. Problem
      2. Solution
      3. Discussion
    7. 10.6. Opening a File by Name
      1. Problem
      2. Solution
      3. Discussion
    8. 10.7. Copying a File
      1. Problem
      2. Solution
      3. Discussion
    9. 10.8. Reading a File into a String
      1. Problem
      2. Solution
      3. Discussion
    10. 10.9. Reassigning the Standard Streams
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 10.10. Duplicating a Stream as It Is Written
      1. Problem
      2. Solution
      3. Discussion
    12. 10.11. Reading/Writing a Different Character Set
      1. Problem
      2. Solution
      3. Discussion
    13. 10.12. Those Pesky End-of-Line Characters
      1. Problem
      2. Solution
      3. Discussion
    14. 10.13. Beware Platform-Dependent File Code
      1. Problem
      2. Solution
      3. Discussion
    15. 10.14. Reading "Continued" Lines
      1. Problem
      2. Solution
      3. Discussion
    16. 10.15. Binary Data
      1. Problem
      2. Solution
      3. Discussion
    17. 10.16. Seeking
      1. Problem
      2. Solution
      3. Discussion
    18. 10.17. Writing Data Streams from C
      1. Problem
      2. Solution
      3. Discussion
    19. 10.18. Saving and Restoring Java Objects
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. 10.19. Preventing ClassCastExceptions with SerialVersionUID
      1. Problem
      2. Solution
      3. Discussion
    21. 10.20. Reading and Writing JAR or Zip Archives
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    22. 10.21. Reading and Writing Compressed Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    23. 10.22. Program: Text to PostScript
      1. See Also
  14. 11. Directory and Filesystem Operations
    1. Introduction
    2. 11.1. Getting File Information
      1. Problem
      2. Solution
      3. Discussion
    3. 11.2. Creating a File
      1. Problem
      2. Solution
      3. Discussion
    4. 11.3. Renaming a File
      1. Problem
      2. Solution
      3. Discussion
    5. 11.4. Deleting a File
      1. Problem
      2. Solution
      3. Discussion
    6. 11.5. Creating a Transient File
      1. Problem
      2. Solution
      3. Discussion
    7. 11.6. Changing File Attributes
      1. Problem
      2. Solution
      3. Discussion
    8. 11.7. Listing a Directory
      1. Problem
      2. Solution
      3. Discussion
    9. 11.8. Getting the Directory Roots
      1. Problem
      2. Solution
      3. Discussion
    10. 11.9. Creating New Directories
      1. Problem
      2. Solution
      3. Discussion
    11. 11.10. Program: Find
  15. 12. Programming External Devices: Serial and Parallel Ports
    1. Introduction
      1. The Communications API
      2. About the Code Examples in This Chapter
      3. See Also
    2. 12.1. Choosing a Port
      1. Problem
      2. Solution
      3. Discussion
    3. 12.2. Opening a Serial Port
      1. Problem
      2. Solution
      3. Discussion
    4. 12.3. Opening a Parallel Port
      1. Problem
      2. Solution
      3. Discussion
    5. 12.4. Resolving Port Conflicts
      1. Problem
      2. Solution
      3. Discussion
    6. 12.5. Reading and Writing: Lock-Step
      1. Problem
      2. Solution
      3. Discussion
    7. 12.6. Reading and Writing: Event-Driven
      1. Problem
      2. Solution
      3. Discussion
    8. 12.7. Reading and Writing: Threads
      1. Problem
      2. Solution
      3. Discussion
    9. 12.8. Program: Penman Plotter
      1. See Also
  16. 13. Graphics and Sound
    1. Introduction
    2. 13.1. Painting with a Graphics Object
      1. Problem
      2. Solution
      3. Discussion
        1. When to draw?
    3. 13.2. Testing Graphical Components
      1. Problem
      2. Solution
      3. Discussion
    4. 13.3. Drawing Text
      1. Problem
      2. Solution
    5. 13.4. Drawing Centered Text in a Component
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 13.5. Drawing a Drop Shadow
      1. Problem
      2. Solution
      3. Discussion
    7. 13.6. Drawing Text with 2D
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 13.7. Drawing Text with an Application Font
      1. Problem
      2. Solution
      3. Discussion
    9. 13.8. Drawing an Image
      1. Problem
      2. Solution
      3. Discussion
    10. 13.9. Playing a Sound File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 13.10. Playing a Video Clip
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 13.11. Printing in Java
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 13.12. Program: PlotterAWT
    14. 13.13. Program: Grapher
  17. 14. Graphical User Interfaces
    1. Introduction
      1. See Also
    2. 14.1. Displaying GUI Components
      1. Problem
      2. Solution
      3. Discussion
    3. 14.2. Designing a Window Layout
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 14.3. A Tabbed View of Life
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 14.4. Action Handling: Making Buttons Work
      1. Problem
      2. Solution
      3. Discussion
    6. 14.5. Action Handling Using Anonymous Inner Classes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 14.6. Terminating a Program with"Window Close"
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 14.7. Dialogs: When Later Just Won't Do
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 14.8. Catching and Formatting GUI Exceptions
      1. Problem
      2. Solution
      3. Discussion
    10. 14.9. Getting Program Output into a Window
      1. Problem
      2. Solution
      3. Discussion
    11. 14.10. Choosing a Value with JSpinner
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 14.11. Choosing a File with JFileChooser
      1. Problem
      2. Solution
      3. Discussion
    13. 14.12. Choosing a Color
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 14.13. Formatting JComponents with HTML
      1. Problem
      2. Solution
      3. Discussion
    15. 14.14. Centering a Main Window
      1. Problem
      2. Solution
      3. Discussion
    16. 14.15. Changing a Swing Program's Look and Feel
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 14.16. Enhancing Your GUI for Mac OS X
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 14.17. Program: Custom Font Chooser
      1. Problem
      2. Solution
      3. Discussion
    19. 14.18. Program: Custom Layout Manager
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  18. 15. Internationalization and Localization
    1. Introduction
    2. 15.1. Creating a Button with I18N Resources
      1. Problem
      2. Solution
        1. What happens at runtime?
        2. Setting the locale
    3. 15.2. Listing Available Locales
      1. Problem
      2. Solution
      3. Discussion
    4. 15.3. Creating a Menu with I18N Resources
      1. Problem
      2. Solution
      3. Discussion
    5. 15.4. Writing Internationalization Convenience Routines
      1. Problem
      2. Solution
      3. Discussion
    6. 15.5. Creating a Dialog with I18N Resources
      1. Problem
      2. Solution
      3. Discussion
    7. 15.6. Creating a Resource Bundle
      1. Problem
      2. Solution
      3. Discussion
    8. 15.7. Extracting Strings from Your Code
      1. Problem
      2. Solution
      3. Discussion
    9. 15.8. Using a Particular Locale
      1. Problem
      2. Solution
      3. Discussion
    10. 15.9. Setting the Default Locale
      1. Problem
      2. Solution
      3. Discussion
    11. 15.10. Formatting Messages
      1. Problem
      2. Solution
      3. Discussion
    12. 15.11. Program: MenuIntl
    13. 15.12. Program: BusCard
      1. See Also
      2. 15.12.2. Internationalization Caveats
      3. 15.12.3. Documentation
      4. 15.12.4. The Last Word
  19. 16. Network Clients
    1. Introduction
    2. 16.1. Contacting a Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 16.2. Finding and Reporting Network Addresses
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 16.3. Handling Network Errors
      1. Problem
      2. Solution
    5. 16.4. Reading and Writing Textual Data
      1. Problem
      2. Solution
      3. Discussion
    6. 16.5. Reading and Writing Binary Data
      1. Problem
      2. Solution
      3. Discussion
    7. 16.6. Reading and Writing Serialized Data
      1. Problem
      2. Solution
      3. Discussion
    8. 16.7. UDP Datagrams
      1. Problem
      2. Solution
      3. Discussion
    9. 16.8. Program: TFTP UDP Client
    10. 16.9. Program: Telnet Client
    11. 16.10. Program: Chat Client
      1. See Also
  20. 17. Server-Side Java: Sockets
    1. Introduction
    2. 17.1. Opening a Server for Business
      1. Problem
      2. Solution
      3. Discussion
    3. 17.2. Returning a Response (String or Binary)
      1. Problem
      2. Solution
      3. Discussion
    4. 17.3. Returning Object Information
      1. Problem
      2. Solution
      3. Discussion
    5. 17.4. Handling Multiple Clients
      1. Problem
      2. Solution
      3. Discussion
    6. 17.5. Serving the HTTP Protocol
      1. Problem
      2. Solution
      3. Discussion
    7. 17.6. Securing a Web Server with SSL and JSSE
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 17.7. Network Logging
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 17.8. Network Logging with log4j
      1. Problem
      2. Solution
      3. Discussion
    10. 17.9. Network Logging with JDK 1.4
      1. Problem
      2. Solution
      3. Discussion
    11. 17.10. Finding Network Interfaces
      1. Problem
      2. Solution
      3. Discussion
    12. 17.11. Program: A Java Chat Server
      1. See Also
  21. 18. Network Clients II: Applets and Web Clients
    1. Introduction
    2. 18.1. Embedding Java in a Web Page
      1. Problem
      2. Solution
      3. Discussion
    3. 18.2. Applet Techniques
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 18.3. Contacting a Server on the Applet Host
      1. Problem
      2. Solution
      3. Discussion
    5. 18.4. Making an Applet Show a Document
      1. Problem
      2. Solution
      3. Discussion
    6. 18.5. Making an Applet Run JavaScript
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 18.6. Making an Applet Run a CGI Script
      1. Problem
      2. Solution
      3. Discussion
    8. 18.7. Reading the Contents of a URL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 18.8. URI, URL, or URN?
      1. Problem
      2. Solution
      3. Discussion
    10. 18.9. Extracting HTML from a URL
      1. Problem
      2. Solution
      3. Discussion
    11. 18.10. Extracting URLs from a File
      1. Problem
      2. Solution
      3. Discussion
    12. 18.11. Converting a Filename to a URL
      1. Problem
      2. Solution
      3. Discussion
    13. 18.12. Program: MkIndex
    14. 18.13. Program: LinkChecker
      1. 18.13.1. Downloading an Entire Web Site
  22. 19. Java and Electronic Mail
    1. Introduction
    2. 19.1. Sending Email: Browser Version
      1. Problem
      2. Solution
      3. Discussion
    3. 19.2. Sending Email: For Real
      1. Problem
      2. Solution
      3. Discussion
    4. 19.3. Mail-Enabling a Server Program
      1. Problem
      2. Solution
      3. Discussion
    5. 19.4. Sending MIME Mail
      1. Problem
      2. Solution
      3. Discussion
    6. 19.5. Providing Mail Settings
      1. Problem
      2. Solution
      3. Discussion
    7. 19.6. Sending Mail Without Using JavaMail
      1. Problem
      2. Solution
      3. Discussion
    8. 19.7. Reading Email
      1. Problem
      2. Solution
      3. Discussion
    9. 19.8. Program: MailReaderBean
    10. 19.9. Program: MailClient
      1. See Also
  23. 20. Database Access
    1. Introduction
    2. 20.1. Easy Database Access with JDO
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 20.2. Text-File Databases
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 20.3. DBM Databases
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 20.4. JDBC Setup and Connection
      1. Problem
      2. Solution
      3. Discussion
    6. 20.5. Connecting to a JDBC Database
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 20.6. Sending a JDBC Query and Getting Results
      1. Problem
      2. Solution
      3. Discussion
    8. 20.7. Using JDBC Prepared Statements
      1. Problem
      2. Solution
      3. Discussion
    9. 20.8. Using Stored Procedures with JDBC
      1. Problem
      2. Solution
      3. Discussion
    10. 20.9. Changing Data Using a ResultSet
      1. Problem
      2. Solution
      3. Discussion
    11. 20.10. Storing Results in a RowSet
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 20.11. Changing Data Using SQL
      1. Problem
      2. Solution
      3. Discussion
    13. 20.12. Finding JDBC Metadata
      1. Problem
      2. Solution
      3. Discussion
        1. ResultSetMetaData
        2. DatabaseMetaData
    14. 20.13. Program: SQLRunner
      1. See Also
  24. 21. XML
    1. Introduction
    2. 21.1. Generating XML from Objects
      1. Problem
      2. Solution
      3. Discussion
    3. 21.2. Transforming XML with XSLT
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 21.3. Parsing XML with SAX
      1. Problem
      2. Solution
      3. Discussion
    5. 21.4. Parsing XML with DOM
      1. Problem
      2. Solution
      3. Discussion
    6. 21.5. Verifying Structure with a DTD
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 21.6. Generating Your Own XML with DOM
      1. Problem
      2. Solution
      3. Discussion
    8. 21.7. Program: xml2mif
      1. See Also
  25. 22. Distributed Java: RMI
    1. Introduction
    2. 22.1. Defining the RMI Contract
      1. Problem
      2. Solution
      3. Discussion
    3. 22.2. Creating an RMI Client
      1. Problem
      2. Solution
      3. Discussion
    4. 22.3. Creating an RMI Server
      1. Problem
      2. Solution
      3. Discussion
        1. Using the server
      4. See Also
    5. 22.4. Deploying RMI Across a Network
      1. Problem
      2. Solution
      3. Discussion
    6. 22.5. Program: RMI Callbacks
    7. 22.6. Program: NetWatch
      1. See Also
  26. 23. Packages and Packaging
    1. Introduction
    2. 23.1. Creating a Package
      1. Problem
      2. Solution
      3. Discussion
    3. 23.2. Documenting Classes with Javadoc
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 23.3. Beyond JavaDoc: Annotations/Metadata (JDK 1.5) and XDoclet
      1. Problem
      2. Solution
      3. Discussion
      4. 23.3.4. The Annotations Mechanism (JDK 1.5)
    5. 23.4. Archiving with jar
      1. Problem
      2. Solution
      3. Discussion
    6. 23.5. Running an Applet from a JAR
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 23.6. Running an Applet with a Modern JDK
      1. Problem
      2. Solution
      3. Discussion
    8. 23.7. Running a Main Program from a JAR
      1. Problem
      2. Solution
      3. Discussion
      4. 23.7.4. Mac OS X Specifics
    9. 23.8. Preparing a Class as a JavaBean
      1. Problem
      2. Solution
      3. Discussion
    10. 23.9. Pickling Your Bean into a JAR
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 23.10. Packaging a Servlet into a WAR File
      1. Problem
      2. Solution
      3. Discussion
    12. 23.11. "Write Once, Install Anywhere"
      1. Problem
      2. Solution
      3. Discussion
    13. 23.12. "Write Once, Install on Mac OS X"
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 23.13. Java Web Start
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 23.14. Signing Your JAR File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  27. 24. Threaded Java
    1. Introduction
    2. 24.1. Running Code in a Different Thread
      1. Problem
      2. Solution
      3. Discussion
        1. Thread lifecycle methods
    3. 24.2. Displaying a Moving Image with Animation
      1. Problem
      2. Solution
      3. Discussion
    4. 24.3. Stopping a Thread
      1. Problem
      2. Solution
      3. Discussion
    5. 24.4. Rendezvous and Timeouts
      1. Problem
      2. Solution
      3. Discussion
    6. 24.5. Synchronizing Threads with the synchronized Keyword
      1. Problem
      2. Solution
      3. Discussion
    7. 24.6. Simplifying Synchronization with 1.5 Locks
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 24.7. Synchronizing Threads with wait( ) and notifyAll( )
      1. Problem
      2. Solution
      3. Discussion
    9. 24.8. Simplifying Producer-Consumer with the 1.5 Queue Interface
      1. Problem
      2. Solution
      3. Discussion
    10. 24.9. Background Saving in an Editor
      1. Problem
      2. Solution
      3. Discussion
    11. 24.10. Program: Threaded Network Server
      1. Problem
      2. Solution
      3. Discussion
    12. 24.11. Simplifying Servers Using the Concurrency Utilities (JDK 1.5)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  28. 25. Introspection, or "A Class Named Class"
    1. Introduction
    2. 25.1. Getting a Class Descriptor
      1. Problem
      2. Solution
    3. 25.2. Finding and Using Methods and Fields
      1. Problem
      2. Solution
      3. Discussion
    4. 25.3. Loading and Instantiating a Class Dynamically
      1. Problem
      2. Solution
      3. Discussion
    5. 25.4. Constructing a Class from Scratch
      1. Problem
      2. Solution
      3. Discussion
        1. What next?
    6. 25.5. Performance Timing
      1. Problem
      2. Solution
      3. Discussion
        1. Timing results
        2. Timing program
    7. 25.6. Printing Class Information
      1. Problem
      2. Solution
      3. Discussion
    8. 25.7. Program: CrossRef
    9. 25.8. Program: AppletViewer
      1. See Also
  29. 26. Using Java with Other Languages
    1. Introduction
    2. 26.1. Running a Program
      1. Problem
      2. Solution
      3. Discussion
    3. 26.2. Running a Program and Capturing Its Output
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 26.3. Mixing Java and Scripts with BSF
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 26.4. Marrying Java and Perl
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 26.5. Blending in Native Code (C/C++)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 26.6. Calling Java from Native Code
      1. Problem
      2. Solution
      3. Discussion
    8. 26.7. Program: DBM
      1. See Also
  30. Afterword
  31. Index
  32. About the Author
  33. Colophon
  34. Copyright