did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780596007010

Java Cookbook

by
  • ISBN13:

    9780596007010

  • ISBN10:

    0596007019

  • Edition: 2nd
  • Format: Paperback
  • Copyright: 2004-06-30
  • Publisher: Oreilly & Associates Inc
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $49.99 Save up to $5.05
  • Digital
    $44.94
    Add to Cart

    DURATION
    PRICE

Supplemental Materials

What is included with this book?

Summary

The Java Cookbook is a comprehensive collection of problems, solutions, and practical examples for anyone programming in Java. In this major revision, developers will find hundreds of tried-and-true Java "recipes" covering all of the major APIs from the 1.4 version of Java. The book also offers significant "first look" recipes for the most important features of the new 1.5 version, which is in beta release. It also includes expanded Mac OS X Panther coverage, and serves as a great "jumping-off place" for Java developers who want to get started in areas outside of their specialization.

Author Biography

Ian F. Darwin has worked in the computer industry for three decades: with Unix since 1980, Java since 1995, and OpenBSD since 1998. He wrote the freeware file(1) command used on Linux and BSD and is the author of Checking C Programs with Lint, Java Cookbook, and over seventy articles and several courses (both university and commercial) on C and Unix. In addition to programming and consulting, Ian teaches Unix, C, and Java for Learning Tree International, one of the world's largest technical training companies. He runs OpenBSD on most of his computers, and he runs a mirror of The Unix History Society archive.

Table of Contents

Preface xv
1. Getting Started: Compiling, Running, and Debugging 1(34)
1.1 Compiling and Running Java: JDK
1(2)
1.2 Editing and Compiling with a Color-Highlighting Editor
3(1)
1.3 Compiling, Running, and Testing with an IDE
4(7)
1.4 Using CLASSPATH Effectively
11(3)
1.5 Using the com.darwinsys API Classes from This Book
14(1)
1.6 Compiling the Source Code Examples from This Book
15(1)
1.7 Automating Compilation with Ant
16(1)
1.8 Running Applets
17(3)
1.9 Dealing with Deprecation Warnings
20(2)
1.10 Conditional Debugging Without #ifdef
22(2)
1.11 Debugging Printouts
24(1)
1.12 Maintaining Program Correctness with Assertions
25(1)
1.13 Debugging with JDB
26(2)
1.14 Unit Testing: Avoid the Need for Debuggers
28(2)
1.15 Getting Readable Tracebacks
30(2)
1.16 Finding More Java Source Code
32(1)
1.17 Program: Debug
33(2)
2. Interacting with the Environment 35(15)
2.1 Getting Environment Variables
35(2)
2.2 System Properties
37(2)
2.3 Writing JDK Release-Dependent Code
39(1)
2.4 Writing Operating System-Dependent Code
40(2)
2.5 Using Extensions or Other Packaged APIs
42(1)
2.6 Parsing Command-Line Arguments
43(7)
3. Strings and Things 50(35)
3.1 Taking Strings Apart with Substrings
52(1)
3.2 Taking Strings Apart with StringTokenizer
53(3)
3.3 Putting Strings Together with +, StringBuilder (JDK 1.5), and StringBuffer
56(3)
3.4 Processing a String One Character at a Time
59(1)
3.5 Aligning Strings
60(3)
3.6 Converting Between Unicode Characters and Strings
63(1)
3.7 Reversing a String by Word or by Character
64(1)
3.8 Expanding and Compressing Tabs
65(5)
3.9 Controlling Case
70(1)
3.10 Indenting Text Documents
71(2)
3.11 Entering Nonprintable Characters
73(1)
3.12 Trimming Blanks from the End of a String
74(1)
3.13 Parsing Comma-Separated Data
75(5)
3.14 Program: A Simple Text Formatter
80(2)
3.15 Program: Soundex Name Comparisons
82(3)
4. Pattern Matching with Regular Expressions 85(32)
4.1 Regular Expression Syntax
87(7)
4.2 Using regexes in Java: Test for a Pattern
94(3)
4.3 Finding the Matching Text
97(2)
4.4 Replacing the Matched Text
99(1)
4.5 Printing All Occurrences of a Pattern
100(3)
4.6 Printing Lines Containing a Pattern
103(1)
4.7 Controlling Case in Regular Expressions
104(1)
4.8 Matching "Accented" or Composite Characters
105(1)
4.9 Matching Newlines in Text
106(2)
4.10 Program: Apache Logfile Parsing
108(2)
4.11 Program: Data Mining
110(2)
4.12 Program: Full Grep
112(5)
5. Numbers 117(37)
5.1 Checking Whether a String Is a Valid Number
119(1)
5.2 Storing a Larger Number in a Smaller Number
120(1)
5.3 Converting Numbers to Objects and Vice Versa
121(1)
5.4 Taking a Fraction of an Integer Without Using Floating Point
122(1)
5.5 Ensuring the Accuracy of Floating-Point Numbers
123(2)
5.6 Comparing Floating-Point Numbers
125(2)
5.7 Rounding Floating-Point Numbers
127(1)
5.8 Formatting Numbers
128(2)
5.9 Converting Between Binary, Octal, Decimal, and Hexadecimal
130(1)
5.10 Operating on a Series of Integers
131(1)
5.11 Working with Roman Numerals
132(4)
5.12 Formatting with Correct Plurals
136(2)
5.13 Generating Random Numbers
138(1)
5.14 Generating Better Random Numbers
139(1)
5.15 Calculating Trigonometric Functions
140(1)
5.16 Taking Logarithms
141(1)
5.17 Multiplying Matrices
141(2)
5.18 Using Complex Numbers
143(2)
5.19 Handling Very Large Numbers
145(2)
5.20 Program: TempConverter
147(4)
5.21 Program: Number Palindromes
151(3)
6. Dates and Times 154(22)
6.1 Finding Today's Date
155(1)
6.2 Printing Date/Time in a Given Format
156(3)
6.3 Representing Dates in Other Epochs
159(1)
6.4 Converting YMDHMS to a Calendar or Epoch Seconds
160(1)
6.5 Parsing Strings into Dates
161(1)
6.6 Converting Epoch Seconds to DMYHMS
162(1)
6.7 Adding to or Subtracting from a Date or Calendar
163(2)
6.8 Difference Between Two Dates
165(1)
6.9 Comparing Dates
165(2)
6.10 Day of Week/Month/Year or Week Number
167(1)
6.11 Creating a Calendar Page
168(3)
6.12 Measuring Elapsed Time
171(2)
6.13 Sleeping for a While
173(1)
6.14 Program: Reminder Service
173(3)
7. Structuring Data with Java 176(32)
7.1 Using Arrays for Data Structuring
177(1)
7.2 Resizing an Array
178(2)
7.3 Like an Array, but More Dynamic
180(1)
7.4 Using Iterators for Data-Independent Access
181(2)
7.5 Structuring Data in a Linked List
183(2)
7.6 Mapping with Hashtable and HashMap
185(1)
7.7 Storing Strings in Properties and Preferences
186(4)
7.8 Sorting a Collection
190(3)
7.9 Avoiding the Urge to Sort
193(2)
7.10 Eschewing Duplication
195(1)
7.11 Finding an Object in a Collection
196(2)
7.12 Converting a Collection to an Array
198(1)
7.13 Rolling Your Own Iterator
199(2)
7.14 Stack
201(1)
7.15 Multidimensional Structures
202(2)
7.16 Finally, Collections
204(2)
7.17 Program: Timing Comparisons
206(2)
8. Data Structuring with Generics, foreach, and Enumerations (JDK 1.5) 208(14)
8.1 Using Generic Collections
209(1)
8.2 Using "foreach" Loops
210(1)
8.3 Avoid Casting by Using Generics
211(3)
8.4 Let Java Convert with AutoBoxing and AutoUnboxing
214(1)
8.5 Using Typesafe Enumerations
215(4)
8.6 Program: Medialnvoicer
219(3)
9. Object-Oriented Techniques 222(25)
9.1 Printing Objects: Formatting with toString()
224(1)
9.2 Overriding the Equals Method
225(3)
9.3 Overriding the hashCode Method
228(1)
9.4 The Clone Method
229(2)
9.5 The Finalize Method
231(2)
9.6 Using Inner Classes
233(1)
9.7 Providing Callbacks via Interfaces
234(4)
9.8 Polymorphism/Abstract Methods
238(1)
9.9 Passing Values
239(3)
9.10 Enforcing the Singleton Pattern
242(1)
9.11 Roll Your Own Exceptions
243(1)
9.12 Program: Plotter
244(3)
10. Input and Output 247(50)
10.1 Reading Standard Input
248(4)
10.2 Writing Standard Output
252(1)
10.3 Printing with the 1.5 Formatter
253(4)
10.4 Scanning a File with StreamTokenizer
257(5)
10.5 Scanning Input with the 1.5 Scanner Class
262(3)
10.6 Opening a File by Name
265(1)
10.7 Copying a File
266(3)
10.8 Reading a File into a String
269(1)
10.9 Reassigning the Standard Streams
270(1)
10.10 Duplicating a Stream as It Is Written
270(3)
10.11 Reading/Writing a Different Character Set
273(1)
10.12 Those Pesky End-of-Line Characters
274(1)
10.13 Beware Platform-Dependent File Code
274(1)
10.14 Reading "Continued" Lines
275(5)
10.15 Binary Data
280(1)
10.16 Seeking
281(1)
10.17 Writing Data Streams from C
282(2)
10.18 Saving and Restoring Java Objects
284(3)
10.19 Preventing ClassCastExceptions with SerialVersionUID
287(2)
10.20 Reading and Writing JAR or Zip Archives
289(3)
10.21 Reading and Writing Compressed Files
292(1)
10.22 Program: Text to PostScript
293(4)
11. Directory and Filesystem Operations 297(16)
11.1 Getting File Information
297(3)
11.2 Creating a File
300(1)
11.3 Renaming a File
301(1)
11.4 Deleting a File
302(1)
11.5 Creating a Transient File
303(2)
11.6 Changing File Attributes
305(1)
11.7 Listing a Directory
306(2)
11.8 Getting the Directory Roots
308(1)
11.9 Creating New Directories
309(1)
11.10 Program: Find
310(3)
12. Programming External Devices: Serial and Parallel Ports 313(29)
12.1 Choosing a Port
315(3)
12.2 Opening a Serial Port
318(4)
12.3 Opening a Parallel Port
322(3)
12.4 Resolving Port Conflicts
325(3)
12.5 Reading and Writing: Lock-Step
328(3)
12.6 Reading and Writing: Event-Driven
331(4)
12.7 Reading and Writing: Threads
335(2)
12.8 Program: Penman Plotter
337(5)
13. Graphics and Sound 342(30)
13.1 Painting with a Graphics Object
342(2)
13.2 Testing Graphical Components
344(1)
13.3 Drawing Text
344(1)
13.4 Drawing Centered Text in a Component
345(2)
13.5 Drawing a Drop Shadow
347(2)
13.6 Drawing Text with 2D
349(3)
13.7 Drawing Text with an Application Font
352(2)
13.8 Drawing an Image
354(4)
13.9 Playing a Sound File
358(2)
13.10 Playing a Video Clip
360(2)
13.11 Printing in Java
362(4)
13.12 Program: PlotterAWT
366(2)
13.13 Program: Grapher
368(4)
14. Graphical User Interfaces 372(49)
14.1 Displaying GUI Components
373(2)
14.2 Designing a Window Layout
375(3)
14.3 A Tabbed View of Life
378(1)
14.4 Action Handling: Making Buttons Work
379(2)
14.5 Action Handling Using Anonymous Inner Classes
381(2)
14.6 Terminating a Program with "Window Close"
383(4)
14.7 Dialogs: When Later Just Won't Do
387(2)
14.8 Catching and Formatting GUI Exceptions
389(2)
14.9 Getting Program Output into a Window
391(4)
14.10 Choosing a Value with JSpinner
395(1)
14.11 Choosing a File with JFileChooser
396(3)
14.12 Choosing a Color
399(3)
14.13 Formatting JComponents with HTML
402(1)
14.14 Centering a Main Window
403(1)
14.15 Changing a Swing Program's Look and Feel
404(4)
14.16 Enhancing Your GUI for Mac OS X
408(2)
14.17 Program: Custom Font Chooser
410(4)
14.18 Program: Custom Layout Manager
414(7)
15. Internationalization and Localization 421(20)
15.1 Creating a Button with I18N Resources
422(1)
15.2 Listing Available Locales
423(1)
15.3 Creating a Menu with I18N Resources
424(1)
15.4 Writing Internationalization Convenience Routines
425(2)
15.5 Creating a Dialog with I18N Resources
427(1)
15.6 Creating a Resource Bundle
428(1)
15.7 Extracting Strings from Your Code
429(1)
15.8 Using a Particular Locale
430(1)
15.9 Setting the Default Locale
431(1)
15.10 Formatting Messages
432(2)
15.11 Program: MenuIntl
434(2)
15.12 Program: BusCard
436(5)
16. Network Clients 441(26)
16.1 Contacting a Server
443(1)
16.2 Finding and Reporting Network Addresses
444(2)
16.3 Handling Network Errors
446(1)
16.4 Reading and Writing Textual Data
447(2)
16.5 Reading and Writing Binary Data
449(2)
16.6 Reading and Writing Serialized Data
451(2)
16.7 UDP Datagrams
453(2)
16.8 Program: TFTP UDP Client
455(4)
16.9 Program: Telnet Client
459(2)
16.10 Program: Chat Client
461(6)
17. Server-Side Java: Sockets 467(34)
17.1 Opening a Server for Business
467(3)
17.2 Returning a Response (String or Binary)
470(4)
17.3 Returning Object Information
474(1)
17.4 Handling Multiple Clients
475(5)
17.5 Serving the HTTP Protocol
480(2)
17.6 Securing a Web Server with SSL and JSSE
482(2)
17.7 Network Logging
484(5)
17.8 Network Logging with log4j
489(2)
17.9 Network Logging with JDK 1.4
491(2)
17.10 Finding Network Interfaces
493(2)
17.11 Program: A Java Chat Server
495(6)
18. Network Clients II: Applets and Web Clients 501(30)
18.1 Embedding Java in a Web Page
501(2)
18.2 Applet Techniques
503(2)
18.3 Contacting a Server on the Applet Host
505(3)
18.4 Making an Applet Show a Document
508(2)
18.5 Making an Applet Run JavaScript
510(1)
18.6 Making an Applet Run a CGI Script
511(1)
18.7 Reading the Contents of a URL
512(1)
18.8 URI, URL, or URN?
513(2)
18.9 Extracting HTML from a URL
515(2)
18.10 Extracting URLs from a File
517(2)
18.11 Converting a Filename to a URL
519(1)
18.12 Program: MkIndex
519(5)
18.13 Program: LinkChecker
524(7)
19. Java and Electronic Mail 531(39)
19.1 Sending Email: Browser Version
531(4)
19.2 Sending Email: For Real
535(4)
19.3 Mail-Enabling a Server Program
539(4)
19.4 Sending MIME Mail
543(2)
19.5 Providing Mail Settings
545(1)
19.6 Sending Mail Without Using JavaMail
546(4)
19.7 Reading Email
550(5)
19.8 Program: MailReaderBean
555(4)
19.9 Program: MailClient
559(11)
20. Database Access 570(45)
20.1 Easy Database Access with JDO
571(3)
20.2 Text-File Databases
574(5)
20.3 DBM Databases
579(3)
20.4 JDBC Setup and Connection
582(3)
20.5 Connecting to a JDBC Database
585(3)
20.6 Sending a JDBC Query and Getting Results
588(2)
20.7 Using JDBC Prepared Statements
590(4)
20.8 Using Stored Procedures with JDBC
594(1)
20.9 Changing Data Using a ResultSet
595(1)
20.10 Storing Results in a RowSet
596(2)
20.11 Changing Data Using SQL
598(2)
20.12 Finding JDBC Metadata
600(4)
20.13 Program: SQLRunner
604(11)
21. XML 615(19)
21.1 Generating XML from Objects
618(1)
21.2 Transforming XML with XSLT
619(3)
21.3 Parsing XML with SAX
622(2)
21.4 Parsing XML with DOM
624(4)
21.5 Verifying Structure with a DTD
628(2)
21.6 Generating Your Own XML with DOM
630(2)
21.7 Program: xml2mif
632(2)
22. Distributed Java: RMI 634(18)
22.1 Defining the RMI Contract
635(2)
22.2 Creating an RMI Client
637(1)
22.3 Creating an RMI Server
638(3)
22.4 Deploying RMI Across a Network
641(1)
22.5 Program: RMI Callbacks
641(5)
22.6 Program: NetWatch
646(6)
23. Packages and Packaging 652(31)
23.1 Creating a Package
653(1)
23.2 Documenting Classes with Javadoc
653(4)
23.3 Beyond JavaDoc: Annotations/Metadata (JDK 1.5) and XDoclet
657(3)
23.4 Archiving with jar
660(1)
23.5 Running an Applet from a JAR
661(1)
23.6 Running an Applet with a Modern JDK
661(4)
23.7 Running a Main Program from a JAR
665(2)
23.8 Preparing a Class as a JavaBean
667(4)
23.9 Pickling Your Bean into a JAR
671(1)
23.10 Packaging a Servlet into a WAR File
672(1)
23.11 "Write Once, Install Anywhere"
673(1)
23.12 "Write Once, Install on Mac OS X"
673(2)
23.13 Java Web Start
675(6)
23.14 Signing Your JAR File
681(2)
24. Threaded Java 683(42)
24.1 Running Code in a Different Thread
685(3)
24.2 Displaying a Moving Image with Animation
688(4)
24.3 Stopping a Thread
692(2)
24.4 Rendezvous and Timeouts
694(1)
24.5 Synchronizing Threads with the synchronized Keyword
695(6)
24.6 Simplifying Synchronization with 1.5 Locks
701(4)
24.7 Synchronizing Threads with wait() and notifyAll()
705(6)
24.8 Simplifying Producer-Consumer with the 1.5 Queue Interface
711(2)
24.9 Background Saving in an Editor
713(1)
24.10 Program: Threaded Network Server
714(8)
24.11 Simplifying Servers Using the Concurrency Utilities (JDK 1.5)
722(3)
25. Introspection, or "A Class Named Class" 725(27)
25.1 Getting a Class Descriptor
726(1)
25.2 Finding and Using Methods and Fields
727(4)
25.3 Loading and Instantiating a Class Dynamically
731(2)
25.4 Constructing a Class from Scratch
733(1)
25.5 Performance Timing
734(3)
25.6 Printing Class Information
737(2)
25.7 Program: CrossRef
739(6)
25.8 Program: AppletViewer
745(7)
26. Using lava with Other Languages 752(25)
26.1 Running a Program
752(3)
26.2 Running a Program and Capturing Its Output
755(4)
26.3 Mixing Java and Scripts with BSF
759(4)
26.4 Marrying Java and Perl
763(4)
26.5 Blending in Native Code (C/C++)
767(6)
26.6 Calling Java from Native Code
773(1)
26.7 Program: DBM
773(4)
Afterword 777(2)
Index 779

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program