Flylib.com
Java Cookbook, Second Edition
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors:
Ian F Darwin
BUY ON AMAZON
Java Cookbook, 2nd Edition
Table of Contents
Copyright
Preface
Preface to the Second Edition
Preface to the First Edition
Who This Book Is For
What s in This Book?
Platform Notes
Other Books
Conventions Used in This Book
Comments and Questions
Getting the Source Code
Acknowledgments
Chapter 1. Getting Started: Compiling, Running, and Debugging
Introduction
Recipe 1.1 Compiling and Running Java: JDK
Recipe 1.2 Editing and Compiling with a Color-Highlighting Editor
Recipe 1.3 Compiling, Running, and Testing with an IDE
Recipe 1.4 Using CLASSPATH Effectively
Recipe 1.5 Using the com.darwinsys API Classes from This Book
Recipe 1.6 Compiling the Source Code Examples from This Book
Recipe 1.7 Automating Compilation with Ant
Recipe 1.8 Running Applets
Recipe 1.9 Dealing with Deprecation Warnings
Recipe 1.10 Conditional Debugging Without ifdef
Recipe 1.11 Debugging Printouts
Recipe 1.12 Maintaining Program Correctness with Assertions
Recipe 1.13 Debugging with JDB
Recipe 1.14 Unit Testing: Avoid the Need for Debuggers
Recipe 1.15 Getting Readable Tracebacks
Recipe 1.16 Finding More Java Source Code
Recipe 1.17 Program: Debug
Chapter 2. Interacting with the Environment
Introduction
Recipe 2.1 Getting Environment Variables
Recipe 2.2 System Properties
Recipe 2.3 Writing JDK Release-Dependent Code
Recipe 2.4 Writing Operating System-Dependent Code
Recipe 2.5 Using Extensions or Other Packaged APIs
Recipe 2.6 Parsing Command-Line Arguments
Chapter 3. Strings and Things
Introduction
Recipe 3.1 Taking Strings Apart with Substrings
Recipe 3.2 Taking Strings Apart with StringTokenizer
Recipe 3.3 Putting Strings Together with , StringBuilder (JDK 1.5), and StringBuffer
Recipe 3.4 Processing a String One Character at a Time
Recipe 3.5 Aligning Strings
Recipe 3.6 Converting Between Unicode Characters and Strings
Recipe 3.7 Reversing a String by Word or by Character
Recipe 3.8 Expanding and Compressing Tabs
Recipe 3.9 Controlling Case
Recipe 3.10 Indenting Text Documents
Recipe 3.11 Entering Nonprintable Characters
Recipe 3.12 Trimming Blanks from the End of a String
Recipe 3.13 Parsing Comma-Separated Data
Recipe 3.14 Program: A Simple Text Formatter
Recipe 3.15 Program: Soundex Name Comparisons
Chapter 4. Pattern Matching with Regular Expressions
Introduction
Recipe 4.1 Regular Expression Syntax
Recipe 4.2 Using regexes in Java: Test for a Pattern
Recipe 4.3 Finding the Matching Text
Recipe 4.4 Replacing the Matched Text
Recipe 4.5 Printing All Occurrences of a Pattern
Recipe 4.6 Printing Lines Containing a Pattern
Recipe 4.7 Controlling Case in Regular Expressions
Recipe 4.8 Matching
Recipe 4.9 Matching Newlines in Text
Recipe 4.10 Program: Apache Logfile Parsing
Recipe 4.11 Program: Data Mining
Recipe 4.12 Program: Full Grep
Chapter 5. Numbers
Introduction
Recipe 5.1 Checking Whether a String Is a Valid Number
Recipe 5.2 Storing a Larger Number in a Smaller Number
Recipe 5.3 Converting Numbers to Objects and Vice Versa
Recipe 5.4 Taking a Fraction of an Integer Without Using Floating Point
Recipe 5.5 Ensuring the Accuracy of Floating-Point Numbers
Recipe 5.6 Comparing Floating-Point Numbers
Recipe 5.7 Rounding Floating-Point Numbers
Recipe 5.8 Formatting Numbers
Recipe 5.9 Converting Between Binary, Octal, Decimal, and Hexadecimal
Recipe 5.10 Operating on a Series of Integers
Recipe 5.11 Working with Roman Numerals
Recipe 5.12 Formatting with Correct Plurals
Recipe 5.13 Generating Random Numbers
Recipe 5.14 Generating Better Random Numbers
Recipe 5.15 Calculating Trigonometric Functions
Recipe 5.16 Taking Logarithms
Recipe 5.17 Multiplying Matrices
Recipe 5.18 Using Complex Numbers
Recipe 5.19 Handling Very Large Numbers
Recipe 5.20 Program: TempConverter
Recipe 5.21 Program: Number Palindromes
Chapter 6. Dates and Times
Introduction
Recipe 6.1 Finding Today s Date
Recipe 6.2 Printing DateTime in a Given Format
Recipe 6.3 Representing Dates in Other Epochs
Recipe 6.4 Converting YMDHMS to a Calendar or Epoch Seconds
Recipe 6.5 Parsing Strings into Dates
Recipe 6.6 Converting Epoch Seconds to DMYHMS
Recipe 6.7 Adding to or Subtracting from a Dateor Calendar
Recipe 6.8 Difference Between Two Dates
Recipe 6.9 Comparing Dates
Recipe 6.10 Day of WeekMonthYear or Week Number
Recipe 6.11 Creating a Calendar Page
Recipe 6.12 Measuring Elapsed Time
Recipe 6.13 Sleeping for a While
Recipe 6.14 Program: Reminder Service
Chapter 7. Structuring Data with Java
Introduction
Recipe 7.1 Using Arrays for Data Structuring
Recipe 7.2 Resizing an Array
Recipe 7.3 Like an Array, but More Dynamic
Recipe 7.4 Using Iterators for Data-Independent Access
Recipe 7.5 Structuring Data in a Linked List
Recipe 7.6 Mapping with Hashtable and HashMap
Recipe 7.7 Storing Strings in Properties and Preferences
Recipe 7.8 Sorting a Collection
Recipe 7.9 Avoiding the Urge to Sort
Recipe 7.10 Eschewing Duplication
Recipe 7.11 Finding an Object in a Collection
Recipe 7.12 Converting a Collection to an Array
Recipe 7.13 Rolling Your Own Iterator
Recipe 7.14 Stack
Recipe 7.15 Multidimensional Structures
Recipe 7.16 Finally, Collections
Recipe 7.17 Program: Timing Comparisons
Chapter 8. Data Structuring with Generics, foreach, and Enumerations (JDK 1.5)
Introduction
Recipe 8.1 Using Generic Collections
Recipe 8.2 Using
Recipe 8.3 Avoid Casting by Using Generics
Recipe 8.4 Let Java Convert with AutoBoxing and AutoUnboxing
Recipe 8.5 Using Typesafe Enumerations
Recipe 8.6 Program: MediaInvoicer
Chapter 9. Object-Oriented Techniques
Introduction
Recipe 9.1 Printing Objects: Formatting with toString( )
Recipe 9.2 Overriding the Equals Method
Recipe 9.3 Overriding the hashCode Method
Recipe 9.4 The Clone Method
Recipe 9.5 The Finalize Method
Recipe 9.6 Using Inner Classes
Recipe 9.7 Providing Callbacks via Interfaces
Recipe 9.8 PolymorphismAbstract Methods
Recipe 9.9 Passing Values
Recipe 9.10 Enforcing the Singleton Pattern
Recipe 9.11 Roll Your Own Exceptions
Recipe 9.12 Program: Plotter
Chapter 10. Input and Output
Introduction
Recipe 10.1 Reading Standard Input
Recipe 10.2 Writing Standard Output
Recipe 10.3 Printing with the 1.5 Formatter
Recipe 10.4 Scanning a File with StreamTokenizer
Recipe 10.5 Scanning Input with the 1.5 Scanner Class
Recipe 10.6 Opening a File by Name
Recipe 10.7 Copying a File
Recipe 10.8 Reading a File into a String
Recipe 10.9 Reassigning the Standard Streams
Recipe 10.10 Duplicating a Stream as It Is Written
Recipe 10.11 ReadingWriting a Different Character Set
Recipe 10.12 Those Pesky End-of-Line Characters
Recipe 10.13 Beware Platform-Dependent File Code
Recipe 10.14 Reading
Recipe 10.15 Binary Data
Recipe 10.16 Seeking
Recipe 10.17 Writing Data Streams from C
Recipe 10.18 Saving and Restoring Java Objects
Recipe 10.19 Preventing ClassCastExceptions with SerialVersionUID
Recipe 10.20 Reading and Writing JAR or Zip Archives
Recipe 10.21 Reading and Writing Compressed Files
Recipe 10.22 Program: Text to PostScript
Chapter 11. Directory and Filesystem Operations
Introduction
Recipe 11.1 Getting File Information
Recipe 11.2 Creating a File
Recipe 11.3 Renaming a File
Recipe 11.4 Deleting a File
Recipe 11.5 Creating a Transient File
Recipe 11.6 Changing File Attributes
Recipe 11.7 Listing a Directory
Recipe 11.8 Getting the Directory Roots
Recipe 11.9 Creating New Directories
Recipe 11.10 Program: Find
Chapter 12. Programming External Devices: Serial and Parallel Ports
Introduction
Recipe 12.1 Choosing a Port
Recipe 12.2 Opening a Serial Port
Recipe 12.3 Opening a Parallel Port
Recipe 12.4 Resolving Port Conflicts
Recipe 12.5 Reading and Writing: Lock-Step
Recipe 12.6 Reading and Writing: Event-Driven
Recipe 12.7 Reading and Writing: Threads
Recipe 12.8 Program: Penman Plotter
Chapter 13. Graphics and Sound
Introduction
Recipe 13.1 Painting with a Graphics Object
Recipe 13.2 Testing Graphical Components
Recipe 13.3 Drawing Text
Recipe 13.4 Drawing Centered Text in a Component
Recipe 13.5 Drawing a Drop Shadow
Recipe 13.6 Drawing Text with 2D
Recipe 13.7 Drawing Text with an Application Font
Recipe 13.8 Drawing an Image
Recipe 13.9 Playing a Sound File
Recipe 13.10 Playing a Video Clip
Recipe 13.11 Printing in Java
Recipe 13.12 Program: PlotterAWT
Recipe 13.13 Program: Grapher
Chapter 14. Graphical User Interfaces
Introduction
Recipe 14.1 Displaying GUI Components
Recipe 14.2 Designing a Window Layout
Recipe 14.3 A Tabbed View of Life
Recipe 14.4 Action Handling: Making Buttons Work
Recipe 14.5 Action Handling Using Anonymous Inner Classes
Recipe 14.6 Terminating a Program with
Recipe 14.7 Dialogs: When Later Just Won t Do
Recipe 14.8 Catching and Formatting GUI Exceptions
Recipe 14.9 Getting Program Output into a Window
Recipe 14.10 Choosing a Value with JSpinner
Recipe 14.11 Choosing a File with JFileChooser
Recipe 14.12 Choosing a Color
Recipe 14.13 Formatting JComponents with HTML
Recipe 14.14 Centering a Main Window
Recipe 14.15 Changing a Swing Program s Look and Feel
Recipe 14.16 Enhancing Your GUI for Mac OS X
Recipe 14.17 Program: Custom Font Chooser
Recipe 14.18 Program: Custom Layout Manager
Chapter 15. Internationalization and Localization
Introduction
Recipe 15.1 Creating a Button with I18N Resources
Recipe 15.2 Listing Available Locales
Recipe 15.3 Creating a Menu with I18N Resources
Recipe 15.4 Writing Internationalization Convenience Routines
Recipe 15.5 Creating a Dialog with I18N Resources
Recipe 15.6 Creating a Resource Bundle
Recipe 15.7 Extracting Strings from Your Code
Recipe 15.8 Using a Particular Locale
Recipe 15.9 Setting the Default Locale
Recipe 15.10 Formatting Messages
Recipe 15.11 Program: MenuIntl
Recipe 15.12 Program: BusCard
Chapter 16. Network Clients
Introduction
Recipe 16.1 Contacting a Server
Recipe 16.2 Finding and Reporting Network Addresses
Recipe 16.3 Handling Network Errors
Recipe 16.4 Reading and Writing Textual Data
Recipe 16.5 Reading and Writing Binary Data
Recipe 16.6 Reading and Writing Serialized Data
Recipe 16.7 UDP Datagrams
Recipe 16.8 Program: TFTP UDP Client
Recipe 16.9 Program: Telnet Client
Recipe 16.10 Program: Chat Client
Chapter 17. Server-Side Java: Sockets
Introduction
Recipe 17.1 Opening a Server for Business
Recipe 17.2 Returning a Response (String or Binary)
Recipe 17.3 Returning Object Information
Recipe 17.4 Handling Multiple Clients
Recipe 17.5 Serving the HTTP Protocol
Recipe 17.6 Securing a Web Server with SSL and JSSE
Recipe 17.7 Network Logging
Recipe 17.8 Network Logging with log4j
Recipe 17.9 Network Logging with JDK 1.4
Recipe 17.10 Finding Network Interfaces
Recipe 17.11 Program: A Java Chat Server
Chapter 18. Network Clients II: Applets and Web Clients
Introduction
Recipe 18.1 Embedding Java in a Web Page
Recipe 18.2 Applet Techniques
Recipe 18.3 Contacting a Server on the Applet Host
Recipe 18.4 Making an Applet Show a Document
Recipe 18.5 Making an Applet Run JavaScript
Recipe 18.6 Making an Applet Run a CGI Script
Recipe 18.7 Reading the Contents of a URL
Recipe 18.8 URI, URL, or URN?
Recipe 18.9 Extracting HTML from a URL
Recipe 18.10 Extracting URLs from a File
Recipe 18.11 Converting a Filename to a URL
Recipe 18.12 Program: MkIndex
Recipe 18.13 Program: LinkChecker
Chapter 19. Java and Electronic Mail
Introduction
Recipe 19.1 Sending Email: Browser Version
Recipe 19.2 Sending Email: For Real
Recipe 19.3 Mail-Enabling a Server Program
Recipe 19.4 Sending MIME Mail
Recipe 19.5 Providing Mail Settings
Recipe 19.6 Sending Mail Without Using JavaMail
Recipe 19.7 Reading Email
Recipe 19.8 Program: MailReaderBean
Recipe 19.9 Program: MailClient
Chapter 20. Database Access
Introduction
Recipe 20.1 Easy Database Access with JDO
Recipe 20.2 Text-File Databases
Recipe 20.3 DBM Databases
Recipe 20.4 JDBC Setup and Connection
Recipe 20.5 Connecting to a JDBC Database
Recipe 20.6 Sending a JDBC Query and Getting Results
Recipe 20.7 Using JDBC Prepared Statements
Recipe 20.8 Using Stored Procedures with JDBC
Recipe 20.9 Changing Data Using a ResultSet
Recipe 20.10 Storing Results in a RowSet
Recipe 20.11 Changing Data Using SQL
Recipe 20.12 Finding JDBC Metadata
Recipe 20.13 Program: SQLRunner
Chapter 21. XML
Introduction
Recipe 21.1 Generating XML from Objects
Recipe 21.2 Transforming XML with XSLT
Recipe 21.3 Parsing XML with SAX
Recipe 21.4 Parsing XML with DOM
Recipe 21.5 Verifying Structure with a DTD
Recipe 21.6 Generating Your Own XML with DOM
Recipe 21.7 Program: xml2mif
Chapter 22. Distributed Java: RMI
Introduction
Recipe 22.1 Defining the RMI Contract
Recipe 22.2 Creating an RMI Client
Recipe 22.3 Creating an RMI Server
Recipe 22.4 Deploying RMI Across a Network
Recipe 22.5 Program: RMI Callbacks
Recipe 22.6 Program: NetWatch
Chapter 23. Packages and Packaging
Introduction
Recipe 23.1 Creating a Package
Recipe 23.2 Documenting Classes with Javadoc
Recipe 23.3 Beyond JavaDoc: AnnotationsMetadata (JDK 1.5) and XDoclet
Recipe 23.4 Archiving with jar
Recipe 23.5 Running an Applet from a JAR
Recipe 23.6 Running an Applet with a Modern JDK
Recipe 23.7 Running a Main Program from a JAR
Recipe 23.8 Preparing a Class as a JavaBean
Recipe 23.9 Pickling Your Bean into a JAR
Recipe 23.10 Packaging a Servlet into a WAR File
Recipe 23.11
Recipe 23.12
Recipe 23.13 Java Web Start
Recipe 23.14 Signing Your JAR File
Chapter 24. Threaded Java
Introduction
Recipe 24.1 Running Code in a Different Thread
Recipe 24.2 Displaying a Moving Image with Animation
Recipe 24.3 Stopping a Thread
Recipe 24.4 Rendezvous and Timeouts
Recipe 24.5 Synchronizing Threads with the synchronized Keyword
Recipe 24.6 Simplifying Synchronization with 1.5 Locks
Recipe 24.7 Synchronizing Threads with wait( ) and notifyAll( )
Recipe 24.8 Simplifying Producer-Consumer with the 1.5 Queue Interface
Recipe 24.9 Background Saving in an Editor
Recipe 24.10 Program: Threaded Network Server
Recipe 24.11 Simplifying Servers Using the Concurrency Utilities (JDK 1.5)
Chapter 25. Introspection, or
Introduction
Recipe 25.1 Getting a Class Descriptor
Recipe 25.2 Finding and Using Methods and Fields
Recipe 25.3 Loading and Instantiating a Class Dynamically
Recipe 25.4 Constructing a Class from Scratch
Recipe 25.5 Performance Timing
Recipe 25.6 Printing Class Information
Recipe 25.7 Program: CrossRef
Recipe 25.8 Program: AppletViewer
Chapter 26. Using Java with Other Languages
Introduction
Recipe 26.1 Running a Program
Recipe 26.2 Running a Program and Capturing Its Output
Recipe 26.3 Mixing Java and Scripts with BSF
Recipe 26.4 Marrying Java and Perl
Recipe 26.5 Blending in Native Code (CC)
Recipe 26.6 Calling Java from Native Code
Recipe 26.7 Program: DBM
Afterword
Colophon
Index
index_SYMBOL
index_A
index_B
index_C
index_D
index_E
index_F
index_G
index_H
index_I
index_J
index_K
index_L
index_M
index_N
index_O
index_P
index_Q
index_R
index_S
index_T
index_U
index_V
index_W
index_X
index_Y
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors:
Ian F Darwin
BUY ON AMAZON
Database Modeling with MicrosoftВ® Visio for Enterprise Architects (The Morgan Kaufmann Series in Data Management Systems)
Object Types, Predicates, and Basic Constraints
Mapping ORM Models to Logical Database Models
Editing Logical Models”Intermediate Aspects
Change Propagation and Round Trip Engineering
Other Features and Best Practices
Beginners Guide to DarkBASIC Game Programming (Premier Press Game Development)
Welcome to DarkBASIC
Looping Commands
Multiplayer Programming The Crazy Carnage Game
Epilogue
Appendix A Answers to the Chapter Quizzes
C++ How to Program (5th Edition)
do...while Repetition Statement
Creating a Sequential File
Self-Review Exercises
Summary
I.3. FAQs
Wireless Hacks: Tips & Tools for Building, Extending, and Securing Your Network
Hack 6. Use Your Treo as a Modem
Hack 44. Authenticate Wireless Users
Hack 64. Bridge Your Linux AP
Hack 65. Protect Your Bridge with a Firewall
Hack 82. Use Your Orinoco Card with Hermes AP
File System Forensic Analysis
Specific File Systems
NTFS Concepts
The Big Picture
Other Topics
File Name Category
Python Programming for the Absolute Beginner, 3rd Edition
The Compulsory Features List
Threads
Program Exits
Menus
See Jack Hack. Hack, Jack, Hack
flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net
Privacy policy
This website uses cookies. Click
here
to find out more.
Accept cookies