about this book

Welcome to The Well-Grounded Java Developer. This book is aimed at turning you into a Java developer for the modern age, reigniting your passion for both the language and platform. Along the way, you’ll discover new Java 7 features, ensure that you’re familiar with essential modern software techniques (such as dependency injection, test-driven development, and continuous integration), and start to explore the brave new world of non-Java languages on the JVM.

To begin, let’s consider this description of the Java language provided by James Iry in a wonderful blog post “A Brief, Incomplete, and Mostly Wrong History of Programming Languages”:

1996 – James Gosling invents Java. Java is a relatively verbose, garbage collected, class-based, statically typed, single dispatch, object-oriented language with single implementation inheritance and multiple interface inheritance. Sun loudly heralds Java’s novelty.

While the point of Java’s entry is mostly to set up a gag where C# is given the same write-up, this is not bad as descriptions of languages go. The full blog post contains a bunch of other gems—you can find it on the web at James’ blog (http://james-iry.blogspot.com/). It’s well worth a read in an idle moment.

This does present a very real question. Why are we still talking about a language that is now around 16 years old? Surely it’s stable and not much new or interesting can be said about it?

If that were the case, this would be a short book. We are still talking about it, because one of Java’s greatest strengths has been its ability to build on a few core design decisions, which have proved to be very successful in the marketplace:

These design decisions have kept innovation moving in the Java world—the simple core has kept the barrier to joining the developer community low, and the broad ecosystem has made it easy for newcomers to find pre-existing components that fit their needs.

These traits have kept the Java platform and language strong and vibrant—even if the language has had a historical tendency to change slowly. This trend has continued with Java 7. The language changes are evolutionary, not revolutionary. One major difference with earlier versions, however, is that Java 7 is the first version explicitly released with an eye to the next version. Java 7 contains the groundwork for major language changes in Java 8, due to Oracle’s “Plan B” strategy for releases.

The other big shift in recent years has been the rise of non-Java languages on the JVM. This has led to cross-fertilization between Java and other JVM languages and there’s now a large (and growing) number of projects running completely on the JVM that include Java as one of the languages that they use.

The emergence of the polyglot project, particularly involving languages such as Groovy, Scala, and Clojure, is a major factor in the current Java ecosystem, and is the topic of the final part of the book.

How to use this book

The material in this book is broadly designed to be read end-to-end, but we understand that some readers may want to dive straight into particular topics and have partly catered to that style of reading.

We strongly believe in hands-on learning and so we recommend that readers try out the sample code that comes with the book as they read through the text. The rest of this section deals with how you can approach the book if you are more of a standalone-chapter style of reader.

The Well-Grounded Java Developer is split into four parts:

Part 1 contains two chapters on Java 7. The book uses Java 7 syntax and semantics throughout, so chapter 1, “Introducing Java 7,” should be considered required reading. Chapter 2, “New I/O,” will be of specific interest to developers who work with files, filesystems, and network I/O.

Part 2 contains four chapters (3-6) covering the topics of dependency injection, modern concurrency, classfiles/byte code, and performance tuning.

Part 3 (chapters 7-10) covers polyglot programming on the JVM. Chapter 7 should be considered required reading as it sets the stage by discussing the categorization and use of alternative languages on the JVM. The following three language chapters move from a Java-like language (Groovy), through a hybrid OO-functional language (Scala), to a fully functional one (Clojure). Those languages can be read standalone although developers new to functional programming will probably want to read them in order.

Part 4 (the final four chapters) introduces new material as well as builds on topics that have been introduced earlier. Although the chapters can be read stand-alone, in some sections we assume that you’ve read the earlier chapters and/or already have familiarity with certain topics.

In short, chapter 1 is required reading for the entire book. Chapter 7 can be considered as required reading for part 3. The other chapters can be read in sequence or standalone, but there will be sections in later chapters that assume you’ve read earlier material.

Who should read this book

This book is firmly aimed at Java developers who wants to modernize their knowledge base in both the language and the platform. If you want to get up to speed with what Java 7 has to offer, this is the book for you.

If you are looking to brush up on your techniques and understanding of topics such as dependency injection, concurrency, and test-driven development, this book will give you a good grounding in those topics.

This is also a book for those developers who have acknowledged the polyglot programming trend and want to get started down that path. In particular, if you want to learn about functional programming, then our language chapters (especially Scala and Clojure) will be of great benefit to you.

Roadmap

In part 1 there are just two chapters. Chapter 1 introduces Java 7 with its wealth of small but productivity-enhancing features known collectively as Project Coin. Chapter 2 takes you through the new I/O APIs including an overhaul of the filesystem support, new asynchronous I/O capabilities, and more.

Part 2 contains four chapters on vital techniques. Chapter 3 takes you through a journey of how the industry arrived at dependency injection as a technique and goes on to show a standardized solution in Java with Guice 3. Chapter 4 covers how to deal with modern concurrency properly in Java, a topic that has once more come to the fore as the hardware industry firmly moves to multicore processors. Chapter 5 takes you into the classfiles and bytecode of the JVM, demystifying its secrets and enabling you to understand why Java works the way it does. Chapter 6 takes you through the initial steps in performance tuning your Java applications and understanding areas such as the garbage collector.

Part 3 is about polyglot programming on the JVM and consists of four chapters. Chapter 7 starts the polyglot story and gives you the context of why it’s important and when it’s appropriate to use another language. Chapter 8 is an introduction to Groovy, Java’s dynamic friend. Groovy highlights how a syntactically similar yet dynamic language can provide great productivity boosts for a Java developer. Chapter 9 brings you into the hybrid functional/OO world of Scala. Scala is a language of great power and conciseness. Chapter 10 is for the Lisp fans out there. Clojure is widely lauded as “Lisp done right” and showcases the full power of a functional language on the JVM.

Part 4 takes learning from the first three parts and discusses polyglot techniques in several software development areas. Chapter 11 visits test-driven development and provides a methodology around dealing with mock objects as well as some practical tips. Chapter 12 introduces two widely used tools for your build pipeline (Maven 3) and continuous integration (Jenkins/Hudson) needs. Chapter 13 covers the topic of rapid web development and why Java has been traditionally weak in this area, and offers some new technologies to prototype with (Grails and Compojure). Chapter 14 wraps up and takes a look to the future, including the functional support arriving in Java 8.

Code conventions and downloads

The initial download and installation you’ll need is Java 7. Simply follow the download and installation instructions for the binary you need for the OS you use. You can find binaries and instructions online at Oracle’s website for Java SE: www.oracle.com/technetwork/java/javase/downloads/index.html.

For everything else, head to appendix A where the instructions for the installation and running of the source code can be found.

All source code in the book is in a fixed-width font like this, which sets it off from the surrounding text. In many listings, the code is annotated to point out the key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code. We have tried to format the code so that it fits within the available page space in the book by adding line breaks and using indentation carefully. Sometimes, however, very long lines include line continuation markers.

Source code for all the working examples is available from www.manning.com/TheWell-GroundedJavaDeveloper. Code examples appear throughout the book. Longer listings appear under clear listing headers; shorter listings appear between lines of text.

Software requirements

Java 7 runs on just about every modern platform there is today. As long as you are running on one of the following operating systems you’ll be able to run the source examples:

Most of you will want to try out the code samples in an IDE. Java 7 and the latest versions of Groovy, Scala, and Clojure are fairly well supported by the following versions of the main IDEs:

We used NetBeans 7.1 and Eclipse 3.7.1 to create and run the examples.

Author Online

Purchase of The Well-Grounded Java Developer includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/TheWell-GroundedJavaDeveloper. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.