No matter what language they're programming in, developers always wish things would run faster! Especially when writing mission-critical applications, no one wants to be limited by the programming environment.Java Performance Tuning provides all the details you need to know to "performance tune" any type of Java program and make Java code run significantly faster.Java Performance Tuning contains step-by-step instructions on all aspects of the performance tuning process, right from such early considerations as setting goals, measuring performance, and choosing a compiler. Extensive examples for tuning many parts of an application are described in detail, and any pitfalls are identified. The book also provides performance tuning checklists that enable developers to make their tuning as comprehensive as possible.Java Performance Tuning is a book to help you "roll up your sleeves" and examine your code in detail in order to apply different tuning techniques to produce the best possible result.The book shows you how to:

Create and plan a tuning strategy

Avoid performance penalties from inefficient code

Minimize the number of objects a program creates

Improve the behavior of loops and switches

Use threads effectively

Chapter 1 Introduction

Why Is It Slow?

The Tuning Game

System Limitations and What to Tune

A Tuning Strategy

Perceived Performance

Starting to Tune

What to Measure

Don’t Tune What You Don’t Need to Tune

Performance Checklist

Chapter 2 Profiling Tools

Measurements and Timings

Garbage Collection

Method Calls

Object-Creation Profiling

Monitoring Gross Memory Usage

Client/Server Communications

Performance Checklist

Chapter 3 Underlying JDK Improvements

Garbage Collection

Replacing JDK Classes

Faster VMs

Better Optimizing Compilers

Sun’s Compiler and Runtime Optimizations

Compile to Native Machine Code

Native Method Calls

Uncompressed ZIP/JAR Files

Performance Checklist

Chapter 4 Object Creation

Object-Creation Statistics

Object Reuse

Avoiding Garbage Collection

Initialization

Early and Late Initialization

Performance Checklist

Chapter 5 Strings

The Performance Effects of Strings

Compile-Time Versus Runtime Resolution of Strings

Conversions to Strings

Strings Versus char Arrays

String Comparisons and Searches

Sorting Internationalized Strings

Performance Checklist

Chapter 6 Exceptions, Casts, and Variables

Exceptions

Casts

Variables

Method Parameters

Performance Checklist

Chapter 7 Loops and Switches

Java.io.Reader Converter

Exception-Terminated Loops

Switches

Recursion

Recursion and Stacks

Performance Checklist

Chapter 8 I/O, Logging, and Console Output

Replacing System.out

Logging

From Raw I/O to Smokin’ I/O

Serialization

Clustering Objects and Counting I/O Operations

Compression

Performance Checklist

Chapter 9 Sorting

Avoiding Unnecessary Sorting Overhead

An Efficient Sorting Framework

Better Than O(nlogn) Sorting

Performance Checklist

Chapter 10 Threading

User-Interface Thread and Other Threads

Race Conditions

Deadlocks

Synchronization Overheads

Timing Multithreaded Tests

Atomic Access and Assignment

Thread Pools

Load Balancing

Threaded Problem-Solving Strategies

Performance Checklist

Chapter 11 Appropriate Data Structures and Algorithms

Collections

Java 2 Collections

Hashtables and HashMaps

Cached Access

Caching Example I

Caching Example II

Finding the Index for Partially Matched Strings

Search Trees

Performance Checklist

Chapter 12 Distributed Computing

Tools

Message Reduction

Comparing Communication Layers

Caching

Batching I

Application Partitioning

Batching II

Low-Level Communication Optimizations

Distributed Garbage Collection

Databases

Performance Checklist

Chapter 13 When to Optimize

When Not to Optimize

Tuning Class Libraries and Beans

Analysis

Design and Architecture

Tuning After Deployment

More Factors That Affect Performance

Performance Checklist

Chapter 14 Underlying Operating System and Network Improvements

Hard Disks

CPU

RAM

Network I/O

Performance Checklist

Chapter 15 Further Resources

Books

Magazines

URLs

Profilers

Optimizers

Colophon

Jack Shirazi

Jack Shirazi is an independent consultant. He was an early adopter of Java, and for the last few years has consulted mainly for the financial sector, focusing on Java performance. Before using Java, Jack spent many years tuning Smalltalk applications. Jack's early career involved research in theoretical physics and bioinformatics. Jack has publications in the field of protein structure and is proud to have contributed to some of the core Perl5 modules.

Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The image on the cover of Java Performance Tuning is a stopwatch. Unlike traditional clocks, which track the continuation of time through the minutes and hours of a day, the stopwatch measures elapsed time over short intervals by allowing the user to start and stop it. This is particularly suited to sports: stopwatches (also known as chronographs) were common at English horse races as early as the mid-seventeenth century. However, a stopwatch like the one pictured on the cover is prone to human error: its exactness is limited by the reaction times of the person holding it. Although more precise photographic-electric timers appeared as early as 1892 and were used experimentally in the Olympic Games in Stockholm in 1912, the Olympics continued to rely on handheld stopwatches until 1960 in Rome, when the transition was officially made to electric timers. Emily Quill was the production editor and proofreader for Java Performance Tuning. Mary Anne Weeks Mayo was the copyeditor for the book. Jane Ellin and Nancy Kotary performed quality control reviews. Nancy Williams provided production assistance. Nancy Crumpton wrote the index. This colophon was written by Emily Quill.Hanna Dyer designed the cover of this book, based on a series design by Edie Freedman. The image of the stopwatch is from the Stock Options photo collection. It was manipulated in Adobe Photoshop by Michael Snow. The cover layout was produced by Emma Colby using QuarkXPress 4.1, the Bodoni Black font from URW Software, and BT Bodoni Bold Italic from Bitstream. Alicia Cech and David Futato designed the interior layout, based on a series design by Nancy Priest.Text was produced in FrameMaker 5.5.6 using a template implemented by Mike Sierra. The heading font is Bodoni BT; the text font is New Baskerville. Illustrations that appear in the book were created in Macromedia Freehand 8 and Adobe Photoshop 5 by Robert Romano and Rhon Porter.Whenever possible, our books use a durable and flexible lay-flat binding. If the page count exceeds the maximum bulk possible for this type of binding, perfect binding is used.

This book is one of the best-written, most informative Java books I have ever read. It does an excellent job presenting numerous case studies where application performance can be improved with minor and/or major changes. By providing a comparison of the runtime for each different method used, it shows developers how much gain they can expect for their effort. The author also explains in easy to understand English why the changes have the effect they do, making the book more than just a collection of copyable hacks. The one complaint I have about this book is that it does not cover enough topics. I would like to see it cover JDBC in more detail. In addition, comparisons of native compilers (e.g. TowerJ) to the JVMs would be helpful. Perhaps a second edition or a volume two could provide more case studies. However, I think this book is a must have for anyone who is trying to write fast Java programs.