Review:
Thinking in Java, by Bruce Eckel
| Publisher: |
Prentice Hall |
| Copyright: |
2006 |
| Printing: |
October 2009 |
| ISBN: |
0-13-187248-6 |
| Format: |
Trade paperback |
| Pages: |
1461 |
Thinking in Java has gone through multiple editions. This review
is of the 4th edition, which is targetted at Java 5 (with some minor
updates for Java 6, released as it was going to press).
Prior to reading this book, I'd never written code from scratch in Java
and had never learned anything about Java in a structured fashion. My CS
degrees come before the era of ubiquitous Java; the most I'd ever done
with the language was look over and make some minor fixes to code other
people had written, using general programming knowledge. I choose this
book as my introduction because I was looking for a ground-up introduction
with good reviews and was avoiding books that contained a printed version
of the Java library documentation. I can get that myself on-line.
I kept a set of notes on
my
impressions of the Java language itself separately and will not get into
that here. This is, instead, a review of
Thinking in Java as a
book and as a training tool for someone who wants to pick up the language.
First off, this is a remarkably well-titled book, much more so than the
typical programming language book. Eckel is not just teaching Java as one
programming language among many. He tries hard to teach the reader to
think in Java, with a lot of attention to idiomatic use of the language
and natural ways to use its expressiveness. This is exactly what I was
looking for I don't want to just write C or Perl in Java
syntax and I was very satisfied with the result. The book
is also very heavy on source code examples; this is much of the reason why
it's 1,461 pages. Eckel illustrates everything with Java code, generally
complete functioning short programs. Even exploratory musings and
experiments are implemented as Java code. I don't think there's any
significant thought in this book that isn't shown in both text and in
explained Java code.
Eckel has also clearly put significant effort into choosing good examples
and designing his sample programs. I have some past (mild) experience
with object-oriented design, and a lot of experience with higher-level
system design, and I was satisfied and occasionally intrigued by the
object structures and design tips that Eckel provides. He uses design
pattern language heavily, but not in a confusing way, and he takes some
time to explain typical design patterns and illustrate them repeatedly.
This is a solid introduction to good object-oriented program design as
well as an introduction to Java.
One oddity of this book, though, is that Eckel introduces the language
from the ground up, starting with syntax and basic types, and is very
careful not to use any concepts before he introduces them. The result is
a very thorough introduction to the Java language, but it means that it
takes 900 pages (!) before Eckel introduces I/O and the possibility of
writing a useful program based on just the information in the book. This
is for entirely sound conceptual reasons: I/O in Java relies on lots of
concepts, like exceptions and generics, that require extensive
introduction and discussion. However, it does mean that through well more
than half of a monumental tome the reader is learning the language through
rather artificial programs.
I have extensive prior programming background and a high tolerance for
more abstract examples (I have a master's degree in software theory), so I
could deal with this, but even with that background I was starting to feel
like my head was getting too full and too crowded with concepts without
being able to make them concrete. It probably would have helped to work
through some of the exercises, but I dislike exercises that aren't
grounded in some problem I personally want to solve. If you're someone
who only learns languages through practical application, this approach to
teaching the language may drive you nuts, and you may want to look for
another book that compromises conceptual progression to get you started
faster.
Related to this,
Thinking in Java is not about the standard
library. It's about the language, and the vast majority of this book is
focused directly on the language level: inheritance, information hiding,
generics, exceptions, introspection, concurrency, annotations,
serialization, and so forth. The only parts of the standard library that
Eckel covers in depth are the container classes, I/O, and a somewhat odd
and misplaced final chapter on Swing. There is nothing about databases,
essentially nothing about web applications or containers, no network
programming, and very little in the way of practical, applied problems.
As you might guess from the combination of that limitation of scope and
the length of this book, that means it is extremely comprehensive; I doubt
there are many corners of the basic language semantics, including around
generics, that Eckel leaves unexplored. This is exactly what I wanted (I
know how to read library documentation myself and all language core
libraries start looking mostly the same after you've programmed in five or
six languages), but it's very different from the typical approach of a
programming language book. Don't be surprised.
This biggest problem with
Thinking in Java from my perspective is
that it defers many interesting topics to Eckel's web pages and to free
companion books and material that is supposedly found there, to the point
of advertising that on the cover. This is a good way to allow the reader
to explore extra topics that are of specific interest while skipping
others, provided that one actually delivers on that promise. However,
Eckel's web site is dire. The first time I looked at it earlier this year
I was unable to find most of the supplemental material the book promises
is there, and now www.mindview.net doesn't resolve in DNS. I've found
copies of some of that material hosted elsewhere in Google searches, but
this is a rather frustrating experience if one was relying on that
supplemental material to fill in the gaps. And the book is clearly
written expecting people to go look at the web materials; Eckel refers to
them probably a hundred times over the course of the book.
Less of a serious problem, and more of a quirk, is the closing chapter on
Swing. This chapter really doesn't fit much with the book. I suppose
Eckel felt obligated to put in at least one chapter on some concrete
applied topic (I personally would have preferred databases be that topic,
but oh well), and it does serve a useful purpose in showing how
concurrency, inner classes, inheritance, and introspection all work
together in a significant Java library. But it's not presented as just an
example, and it fits in oddly with the rest of the book. It also has an
inexplicable middle section about Flash programming. I ended up mostly
skimming this. But this isn't much of a flaw in the book; if one ignores
100 pages out of 1,450, that's not much of a loss.
Eckel comes from a C++ background (he was a founding member of the C++
standardization committee), which shows up most prominantly in the
generics chapter. It's a solid, thorough introduction to Java generics,
but it also has an extensive exploration of all the problems with the Java
erasure model and many, many examples of the things that one would find
intuitive from C++ that don't work the same way in Java. If you come from
a C++ background, this is quite possibly useful; if, like me, you don't
care about C++, it's at best mildly interesting and gets a touch tedious.
There are a few other places where Eckel pokes surprisingly sharp sticks
at the Java designers, but taken in context I think this is a quirk of the
book's conversational style (which is otherwise a feature).
Eckel's love of Python is also somewhat entertaining (particularly the
long advertisement for Python in the introductory chapters of a book on
Java), but has little impact on the book. I think the largest drawback of
it is that all the examples in this book are tested using a Python
framework, which isn't so much a problem with them as a lost opportunity.
They're annotated with metadata used by Eckel's Python test framework, and
in a Java book I would have been much more interested in a good Java test
framework built on top of something like JUnit. Oh well.
Overall, this is a very solid book which, despite being enormous, does not
feel pointlessly padded. It's thorough and exhaustive on its topic, but
there's a point to nearly everything in here. It was also exactly the
Java book I wanted: an introduction to the language, built on a firm
foundation of object-oriented program design, with discussion and pointers
on how to think idiomatically in the language and use it to its fullest
potential, and without mindlessly reproducing the standard library
documentation. If that's also what you're looking for in a Java book, I
recommend it highly. Just know going in what sort of book you're getting,
since its pacing and order of presentation may frustrate some learning
styles.
Rating: 8 out of 10