“Kirk told me I could buy beer at the petrol station,” was the first sentence I heard out of Ben Evans’ mouth. He had come to Crete for an Open Spaces Java conference. I explained that I usually bought petrol at the petrol station, but that there was a shop around the corner that sold beer. Ben looked disappointed. I had lived on this Greek island for five years and had never thought of trying to buy beer at the local BP.

I felt a bit like this while reading this book. I consider myself a Java fundi. I have spent the past 15 years programming Java, writing hundreds of articles, speaking at conferences, and teaching advanced Java courses. And yet, when I read Ben and Martijn’s book, I kept coming across ideas that I hadn’t thought of. They start by explaining the development effort of changing certain parts of the Java ecosystem. Changing the internals of a library is relatively easy, and we might see some improved performance for certain input. Arrays.sort() is now using TimSort, instead of MergeSort. If you sort a partially ordered array, you might see a slight performance improvement without changing your code. Changing the class file format or adding a new VM feature requires a major effort. Ben knows. He sits on the JCP Executive Committee. This book is also about Java 7, so you’ll learn all the new features, such as the syntactic sugar enhancements, switching on Strings, fork/join, and the Java NIO.2.

Concurrency? That’s Thread and synchronized, right? If that’s all you know about multithreading, it’s time to upgrade your skills. As the authors point out, “the area of concurrency is undergoing a massive amount of research at present.” There are daily discussions on the concurrency interest mailing list, and new ideas are emerging all the time. This book shows you how to think about divide-and-conquer and how to avoid some of the safety flaws.

When I saw the chapter on classloading, I thought they had gone a bit too far. Here were the tricks that my friends and I had used to create magical code, laid bare for all to learn! They explain how javap works, a little tool that can give you insight into the bytecode generated by the Java compiler. They also cover the new invokedynamic and explain how it differs from plain reflection.

One chapter that I particularly like is “Understanding performance tuning.” This is the first book since Jack Shirazi’s Java Performance Tuning that has captured the essence of how to make your system faster. I can summarize the chapter in three words: “Measure, don’t guess.” This is the essence of good performance tuning. It’s impossible for a human to guess which code is slow. Instead of offering a single coding trick, this chapter explains performance from a hardware perspective. It also shows you how to measure the performance. An interesting little benchmark tool is their CacheTester class, which shows the cost of cache misses.

Part 3 of the book explains polyglot programming on the JVM. Java is so much more than a Java programming language. It’s also a platform on which other languages can run. We’ve seen an explosion of different types of languages. Some are functional, some are declarative. Some are ports (Jython and JRuby), allowing other languages to run on the JVM. Languages can be dynamic (Groovy) or stable (Java and Scala). There are many reasons to use a non-Java language on the JVM. If you’re starting a new project, look at what’s available before deciding. You might save yourself a lot of boilerplate code.

Ben and Martijn show us three alternative languages: Groovy, Scala, and Clojure. In my opinion, these are the most viable languages at the moment. The authors describe the differences between these languages, how they compare to Java, and their special features. The chapter on each language is just enough to help you figure out which you should be using, without too much technical detail. Don’t expect a reference manual to Groovy; do expect insight on which language is the right one for you.

Next, you’ll gain insight into how to do test-driven development and continuous integration of your system. I found it amusing that the old faithful butler Hudson was so quickly replaced with Jenkins. In any case, these are essential tools for managing your project, along with tools like Checkstyle and FindBugs.

Studying this book will help you become a well-grounded Java developer. Not only that, it will give you tips on how to stay well-grounded. Java is constantly changing. We’ll see lambdas and modularization in the next version. New languages are being designed; the concurrency constructs are being updated. Many of the things that you know are true now might not be true in the future. The lesson is, don’t ever stop learning!

The other day I drove past the petrol station where Ben wanted to buy his beer. Like so many companies in depressed Greece, it had closed. I never did find out if they sold beer.

Dr. Heinz Kabutz
The Java Specialists’ Newsletter