Java Cookbook

As Java continues to evolve, this cookbook continues to grow in tandem with hundreds of hands-on recipes across a broad range of Java topics. Author Ian Darwin gets developers up to speed right away with useful techniques for everything from string handling and functional programming to network communication and AI.

If you're familiar with any release of Java, this book will bolster your knowledge of the language and its many recent changes, including how to apply them in your day-to-day development. Each recipe includes self-contained code solutions that you can freely use, along with a discussion of how and why they work.

Downloadable from GitHub, all code examples compile successfully. This updated edition covers changes up to Java 23 and most of Java 24. You will:

  • Learn how to apply many new and old Java APIs
  • Use the new language features in recent Java versions
  • Understand the code you're maintaining
  • Develop code using standard APIs and good practices
  • Explore the brave new world of current Java development

Ian Darwin has a lifetime of experience in the software industry, having worked with Java across many platforms and types of software, from Java's initial pre-release to the present, from desktop to enterprise to mobile.

1133658629
Java Cookbook

As Java continues to evolve, this cookbook continues to grow in tandem with hundreds of hands-on recipes across a broad range of Java topics. Author Ian Darwin gets developers up to speed right away with useful techniques for everything from string handling and functional programming to network communication and AI.

If you're familiar with any release of Java, this book will bolster your knowledge of the language and its many recent changes, including how to apply them in your day-to-day development. Each recipe includes self-contained code solutions that you can freely use, along with a discussion of how and why they work.

Downloadable from GitHub, all code examples compile successfully. This updated edition covers changes up to Java 23 and most of Java 24. You will:

  • Learn how to apply many new and old Java APIs
  • Use the new language features in recent Java versions
  • Understand the code you're maintaining
  • Develop code using standard APIs and good practices
  • Explore the brave new world of current Java development

Ian Darwin has a lifetime of experience in the software industry, having worked with Java across many platforms and types of software, from Java's initial pre-release to the present, from desktop to enterprise to mobile.

67.99 In Stock
Java Cookbook

Java Cookbook

by Ian F. Darwin
Java Cookbook

Java Cookbook

by Ian F. Darwin

eBook

$67.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

As Java continues to evolve, this cookbook continues to grow in tandem with hundreds of hands-on recipes across a broad range of Java topics. Author Ian Darwin gets developers up to speed right away with useful techniques for everything from string handling and functional programming to network communication and AI.

If you're familiar with any release of Java, this book will bolster your knowledge of the language and its many recent changes, including how to apply them in your day-to-day development. Each recipe includes self-contained code solutions that you can freely use, along with a discussion of how and why they work.

Downloadable from GitHub, all code examples compile successfully. This updated edition covers changes up to Java 23 and most of Java 24. You will:

  • Learn how to apply many new and old Java APIs
  • Use the new language features in recent Java versions
  • Understand the code you're maintaining
  • Develop code using standard APIs and good practices
  • Explore the brave new world of current Java development

Ian Darwin has a lifetime of experience in the software industry, having worked with Java across many platforms and types of software, from Java's initial pre-release to the present, from desktop to enterprise to mobile.


Product Details

ISBN-13: 9781098169930
Publisher: O'Reilly Media, Incorporated
Publication date: 02/06/2025
Sold by: Barnes & Noble
Format: eBook
Pages: 684
File size: 12 MB
Note: This product may take a few minutes to download.

About the Author

Ian Darwin has a lifetime of experience in the software industry, having worked with Java across many platforms and types of software, from Java’s initial pre-release to the present, from desktop to enterprise to mobile. A founding member of Sun/Oracle Java Champions advocacy group, Ian is also the author of the Android Cookbook and several smaller books on related tech. He’s written and taught courses for computer science undergraduates and for leading career development company Learning Tree International.

Table of Contents

Prefacexv
1.Getting Started: Compiling, Running, and Debugging1
1.1Compiling and Running Java: JDK1
1.2Editing and Compiling with a Color-Highlighting Editor3
1.3Compiling, Running, and Testing with an IDE4
1.4Using CLASSPATH Effectively11
1.5Using the com.darwinsys API Classes from This Book14
1.6Compiling the Source Code Examples from This Book15
1.7Automating Compilation with Ant16
1.8Running Applets17
1.9Dealing with Deprecation Warnings20
1.10Conditional Debugging Without #ifdef22
1.11Debugging Printouts24
1.12Maintaining Program Correctness with Assertions25
1.13Debugging with JDB26
1.14Unit Testing: Avoid the Need for Debuggers28
1.15Getting Readable Tracebacks30
1.16Finding More Java Source Code32
1.17Program: Debug33
2.Interacting with the Environment35
2.1Getting Environment Variables35
2.2System Properties37
2.3Writing JDK Release-Dependent Code39
2.4Writing Operating System-Dependent Code40
2.5Using Extensions or Other Packaged APIs42
2.6Parsing Command-Line Arguments43
3.Strings and Things50
3.1Taking Strings Apart with Substrings52
3.2Taking Strings Apart with String Tokenizer53
3.3Putting Strings Together with +, StringBuilder (JDK 1.5), and StringBuffer56
3.4Processing a String One Character at a Time59
3.5Aligning Strings60
3.6Converting Between Unicode Characters and Strings63
3.7Reversing a String by Word or by Character64
3.8Expanding and Compressing Tabs65
3.9Controlling Case70
3.10Indenting Text Documents71
3.11Entering Nonprintable Characters73
3.12Trimming Blanks from the End of a String74
3.13Parsing Comma-Separated Data75
3.14Program: A Simple Text Formatter80
3.15Program: Soundex Name Comparisons82
4.Pattern Matching with Regular Expressions85
4.1Regular Expression Syntax87
4.2Using regexes in Java: Test for a Pattern94
4.3Finding the Matching Text97
4.4Replacing the Matched Text99
4.5Printing All Occurrences of a Pattern100
4.6Printing Lines Containing a Pattern103
4.7Controlling Case in Regular Expressions104
4.8Matching "Accented" or Composite Characters105
4.9Matching Newlines in Text106
4.10Program: Apache Logfile Parsing108
4.11Program: Data Mining110
4.12Program: Full Grep112
5.Numbers117
5.1Checking Whether a String Is a Valid Number119
5.2Storing a Larger Number in a Smaller Number120
5.3Converting Numbers to Objects and Vice Versa121
5.4Taking a Fraction of an Integer Without Using Floating Point122
5.5Ensuring the Accuracy of Floating-Point Numbers123
5.6Comparing Floating-Point Numbers125
5.7Rounding Floating-Point Numbers127
5.8Formatting Numbers128
5.9Converting Between Binary, Octal, Decimal, and Hexadecimal130
5.10Operating on a Series of Integers131
5.11Working with Roman Numerals132
5.12Formatting with Correct Plurals136
5.13Generating Random Numbers138
5.14Generating Better Random Numbers139
5.15Calculating Trigonometric Functions140
5.16Taking Logarithms141
5.17Multiplying Matrices141
5.18Using Complex Numbers143
5.19Handling Very Large Numbers145
5.20Program: TempConverter147
5.21Program: Number Palindromes151
6.Dates and Times154
6.1Finding Today's Date155
6.2Printing Date/Time in a Given Format156
6.3Representing Dates in Other Epochs159
6.4Converting YMDHMS to a Calendar or Epoch Seconds160
6.5Parsing Strings into Dates161
6.6Converting Epoch Seconds to DMYHMS162
6.7Adding to or Subtracting from a Date or Calendar163
6.8Difference Between Two Dates165
6.9Comparing Dates165
6.10Day of Week/Month/Year or Week Number167
6.11Creating a Calendar Page168
6.12Measuring Elapsed Time171
6.13Sleeping for a While173
6.14Program: Reminder Service173
7.Structuring Data with Java176
7.1Using Arrays for Data Structuring177
7.2Resizing an Array178
7.3Like an Array, but More Dynamic180
7.4Using Iterators for Data-Independent Access181
7.5Structuring Data in a Linked List183
7.6Mapping with Hashtable and HashMap185
7.7Storing Strings in Properties and Preferences186
7.8Sorting a Collection190
7.9Avoiding the Urge to Sort193
7.10Eschewing Duplication195
7.11Finding an Object in a Collection196
7.12Converting a Collection to an Array198
7.13Rolling Your Own Iterator199
7.14Stack201
7.15Multidimensional Structures202
7.16Finally, Collections204
7.17Program: Timing Comparisons206
8.Data Structuring with Generics, foreach, and Enumerations (JDK 1.5)208
8.1Using Generic Collections209
8.2Using "foreach" Loops210
8.3Avoid Casting by Using Generics211
8.4Let Java Convert with AutoBoxing and AutoUnboxing214
8.5Using Typesafe Enumerations215
8.6Program: MediaInvoicer219
9.Object-Oriented Techniques222
9.1Printing Objects: Formatting with toString()224
9.2Overriding the Equals Method225
9.3Overriding the hashCode Method228
9.4The Clone Method229
9.5The Finalize Method231
9.6Using Inner Classes233
9.7Providing Callbacks via Interfaces234
9.8Polymorphism/Abstract Methods238
9.9Passing Values239
9.10Enforcing the Singleton Pattern242
9.11Roll Your Own Exceptions243
9.12Program: Plotter244
10.Input and Output247
10.1Reading Standard Input248
10.2Writing Standard Output252
10.3Printing with the 1.5 Formatter253
10.4Scanning a File with Stream Tokenizer257
10.5Scanning Input with the 1.5 Scanner Class262
10.6Opening a File by Name265
10.7Copying a File266
10.8Reading a File into a String269
10.9Reassigning the Standard Streams270
10.10Duplicating a Stream as It Is Written270
10.11Reading/Writing a Different Character Set273
10.12Those Pesky End-of-Line Characters274
10.13Beware Platform-Dependent File Code274
10.14Reading "Continued" Lines275
10.15Binary Data280
10.16Seeking281
10.17Writing Data Streams from C282
10.18Saving and Restoring Java Objects284
10.19Preventing ClassCastExceptions with SerialVersionUID287
10.20Reading and Writing JAR or Zip Archives289
10.21Reading and Writing Compressed Files292
10.22Program: Text to PostScript293
11.Directory and Filesystem Operations297
11.1Getting File Information297
11.2Creating a File300
11.3Renaming a File301
11.4Deleting a File302
11.5Creating a Transient File303
11.6Changing File Attributes305
11.7Listing a Directory306
11.8Getting the Directory Roots308
11.9Creating New Directories309
11.10Program: Find310
12.Programming External Devices: Serial and Parallel Ports313
12.1Choosing a Port315
12.2Opening a Serial Port318
12.3Opening a Parallel Port322
12.4Resolving Port Conflicts325
12.5Reading and Writing: Lock-Step328
12.6Reading and Writing: Event-Driven331
12.7Reading and Writing: Threads335
12.8Program: Penman Plotter337
13.Graphics and Sound342
13.1Painting with a Graphics Object342
13.2Testing Graphical Components344
13.3Drawing Text344
13.4Drawing Centered Text in a Component345
13.5Drawing a Drop Shadow347
13.6Drawing Text with 2D349
13.7Drawing Text with an Application Font352
13.8Drawing an Image354
13.9Playing a Sound File358
13.10Playing a Video Clip360
13.11Printing in Java362
13.12Program: PlotterAWT366
13.13Program: Grapher368
14.Graphical User Interfaces372
14.1Displaying GUI Components373
14.2Designing a Window Layout375
14.3A Tabbed View of Life378
14.4Action Handling: Making Buttons Work379
14.5Action Handling Using Anonymous Inner Classes381
14.6Terminating a Program with "Window Close"383
14.7Dialogs: When Later Just Won't Do387
14.8Catching and Formatting GUI Exceptions389
14.9Getting Program Output into a Window391
14.10Choosing a Value with JSpinner395
14.11Choosing a File with JFileChooser396
14.12Choosing a Color399
14.13Formatting JComponents with HTML402
14.14Centering a Main Window403
14.15Changing a Swing Program's Look and Feel404
14.16Enhancing Your GUI for Mac OS X408
14.17Program: Custom Font Chooser410
14.18Program: Custom Layout Manager414
15.Internationalization and Localization421
15.1Creating a Button with I18N Resources422
15.2Listing Available Locales423
15.3Creating a Menu with I18N Resources424
15.4Writing Internationalization Convenience Routines425
15.5Creating a Dialog with I18N Resources427
15.6Creating a Resource Bundle428
15.7Extracting Strings from Your Code429
15.8Using a Particular Locale430
15.9Setting the Default Locale431
15.10Formatting Messages432
15.11Program: MenuIntl434
15.12Program: BusCard436
16.Network Clients441
16.1Contacting a Server443
16.2Finding and Reporting Network Addresses444
16.3Handling Network Errors446
16.4Reading and Writing Textual Data447
16.5Reading and Writing Binary Data449
16.6Reading and Writing Serialized Data451
16.7UDP Datagrams453
16.8Program: TFTP UDP Client455
16.9Program: Telnet Client459
16.10Program: Chat Client461
17.Sever-Side Java: Sockets467
17.1Opening a Server for Business467
17.2Returning a Response (String or Binary)470
17.3Returning Object Information474
17.4Handling Multiple Clients475
17.5Serving the HTTP Protocol480
17.6Securing a Web Server with SSL and JSSE482
17.7Network Logging484
17.8Network Logging with log4j489
17.9Network Logging with JDK 1.4491
17.10Finding Network Interfaces493
17.11Program: A Java Chat Server495
18.Network Clients II: Applets and Web Clients501
18.1Embedding Java in a Web Page501
18.2Applet Techniques503
18.3Contacting a Server on the Applet Host505
18.4Making an Applet Show a Document508
18.5Making an Applet Run JavaScript510
18.6Making an Applet Run a CGI Script511
18.7Reading the Contents of a URL512
18.8URI, URL, or URN?513
18.9Extracting HTML from a URL515
18.10Extracting URLs from a File517
18.11Converting a Filename to a URL519
18.12Program: MkIndex519
18.13Program: LinkChecker524
19.Java and Electronic Mail531
19.1
From the B&N Reads Blog

Customer Reviews