Authors: Benjamin J Evans and David Flanagan
Audience: Java programmers who have progressed beyond beginner status
Reviewer: Alex Armstrong
Java in a Nutshell has become something of a classic, but the latest edition is very different. Is it still the standard?
The idea of a "in a Nutshell" books is to be concise. Not exactly just a reference guide but not a slow paced step-by-step introduction either. Previous editions of Java in a Nutshell have included a huge number of pages devoted to an almost reference level documentation of the core APIs.
The problem with any reference work on Java is that the subject matter keeps getting bigger. This new edition covers Java 8 and to keep it as compact as possible only the core language details are discussed - the book still runs to 418 pages. If you were a fan of the earlier editions then you need to realize that much of the information you found there is no longer in the new edition. I think that the tighter focus is a good thing and the core APIs are now well documented on the Oracle website to make a detailed printed version unnecessary. However this doesn't rule out the production of a separate In a Nutshell guide to the core Java APIs. There is also arguably material included in this book that probably shouldn't be for something focused on the core Java language. At the end of the day however it is the authors' choice of what is to be considered core that makes the final cut.
Authorship has also changed over the editions. The original author, David Flanagan, is joined in this edition by Benjamin J Evans whose name appears first on the cover.
The book starts off with a focused look at the language elements of Java. Part I is called Introducing Java and it would serve as a memory jog for anyone returning to Java or moving from another language. It is not suitable for a complete beginner.
Chapter 1 is a brief look a the history and position of Java in the current state of things. The book really gets started at Chapter 2, some 17 pages in. This details, in a fairly dry way, the basics of the language, lexical structure, data types, expressions, methods, classes, arrays, reference types and so on.
Chapter 3 is a rapid introduction to object-oriented programming. It goes through the standard topics - classes, fields and methods, creating instances, inheritance, encapsulation, abstract classes/methods. This is enough to get you started and there is a second chapter on object oriented design later.
Chapter 4 deals with the type system, including type inference introduced in Java 8. It covers the ideas of interfaces and generics before moving on to enums, nested types and lambda expressions.
Chapter 5 goes back to object-oriented techniques and design. This is not a "gang of four" patterns-based explanation of design, more a general consideration of issues such as composition v inheritance, interfaces v abstract classes and so on.
The final chapter in this introduction is about memory and concurrency - the basics of memory management, the HotSpot heap and working with threads.
Part II is about using Java and best practices. Chapter 7 explains naming and documentation conventions. Chapter 8 is about Java Collections - including using lambda expressions. Chapter 9 covers basic data formats - text, numbers, date and time. Chapter 10 is on basic file I/O including networking and Chapter 11 is on "meta" programming - class files and class loading, reflection, dynamic proxies and method handles.
The final chapter is about platform tools and profiles and isn't a bad place to finish.
There are plenty of short examples all the way through the book, but the key thing to appreciate is that this is a fast-paced book that presents ideas using technical language where necessary. It doesn't attempt to explain everything in the simplest possible terms. It also deals with topics from the point of view of Java 8, but there are occasional notes on backwards compatibility.
If you are a Java expert or an expert on a specific area of Java then you will find that this book doesn't go far enough - it is by no means a Java and Java ecosystem encyclopedia. It is a very good compromise if you want something reasonably advanced squeezed into a nutshell. No doubt it will continue to grow with each new edition!