Review: Hardcore Java

Posted by Jonathan

Hardcore Java by Robert Simmons, Jr. is targeted at intermediate to advanced Java programmers who want to learn some advanced techniques and underused concepts of Java. The book is organized into 12 chapters over 324 pages.

Harcore Java

The book begins with a brief review of Java’s core concepts like references, runtime type identification, and iterators. Not so popular features like break, continue, labels, and assert are covered before constructors and initialization are discussed. The chapter ends with common mistakes like overuse of System.exit(). Also access issue are covered. Personally I liked this review as most of the visualized items are often not used or misused in Java like using private accessors for instance variables and therefore prohibiting extension of a class.

Chapter 2 is completely devoted to the final keyword. Final constants, parameters, methods, classes and variables are covered. This may sound boring but instead useful hints and concepts are taught. For example Rober Simmons, Jr. shows how to archive conditional compilation in Java.

Chapter 3 covers immutable types and immutable collections while chapter 4 examines the various collection types that are supported in Java. What I didn’t like were the performance hints like using temporal variables to hold query results instead of calling the query inside a loop or using StringBuffer instead of String for appending long Strings. I just read Martin Fowler’s “Refactoring” some days before and he argues that such performance optimizations cost readability and maintainability and I tend to agree. Apart from that chapter 3 and 4 give you a strong background on immutable types and collections and on when to use which collection.

The next chapter is about Exceptions and on how and when to use Exceptions and RuntimeExceptions. The presented advices are sound and useful as many programmers either over- or underuse Exceptions (including myself, I tend to overuse them).

Chapter 6 examines Java’s nested classes like inner class, limited-scope inner class, anonymous inner class, and static inner class. This also a part of Java that is often not clear to many novice programmers and Robert Simmons, Jr. succeeds in clarifying it.

Chapter 7 covers how to use constants in Java. It begins by explaining bit fields and why they are evil. Constant Objects are proposed as an better alternative.

The next chapter, “Data Modeling”, is about how to attack a bigger problem. Gathering requirements, modeling and object relationships are covered briefly. Then mutable objects and constrains are explored. The beginning of the chapter was a little bit too “Waterfall model” for me as I tend to favor agile methods. Then Robert Simmons, Jr. tries to build a framework for decoupling and programming for bigger projects and I liked his approach apart from the design phase.

The book then continues with Java features and patterns that are not so known. Chapter 9 is all about Reflection. Not a very deep API discussion but more a discussion on why to use Reflection and how the main approaches are used. Chapter 10 uses Reflection to build Proxies and introduces their idea. Chapter 11 discusses the lesser know references in Java; weak references, phantom references, and soft references. An overview of ReferenceQueues, Garbage Collection and practical applications make this a very good chapter on references in Java.

The book ends with a preview on JDK 1.5 Tiger and the new features like autoboxing, generics, and for each loops.

In summary this is a very good book on advanced Java features that introduces many patterns that are assumed in J2EE or EJB books. The chapters on the final keyword, on references, and on constant objects should be read by every Java programmer.

Comments

Leave a response