Slashdot Mirror


Hardcore Java

Alex Garrett writes "First, a quibble. Hardcore Java is not hardcore. Hardcore is implementing coroutines in assembly language or creating a full-fledged OO system in 6K. But if you ignore the title and judge the book solely on its merits you'll find that a Java novice will find a good selection of interesting topics and even an expert will learn a few things. The expert will also find plenty of things to disagree with -- some matters of opinion and others of fact." With that start, read on for the rest of Garrett's review of Hardcore Java, a book in which he finds slightly more worth for Java novices than experts. Hardcore Java author Robert Simmons, Jr. pages 400 publisher O'Reilly rating Experts: 4/10; Novices: 6/10 reviewer Alex Garrett ISBN 0596005687 summary The path to Java guru-hood

The two fatal flaws with this book are that it suffers from a lack of cohesion and focus on its audience and that it doesn't present anything new. That the book doesn't present anything new isn't bad if its goal is to summarize, clarify, and educate the novice. But this book doesn't even work for novices because the author has misidentified his audience. At times he writes for the intermediate programmer, at other times he writes for beginners. The confusion over the audience causes the book to leave novices and experts unsatisfied in equal parts.

Detailed Review
Simmons goal is to write a book that helps "transform a [Java] developer from the intermediate level to a true guru." It is his contention that there is a distinct lack of books that target the intermediate to advanced programmer -- his shining exception is the book Secrets of the C++ Masters by Jeff Alger. While I tend to agree with his assessment, I think that he fails for the following reasons: he doesn't stay true to the audience he has chosen and he doesn't say anything particularly new about the topics he covers.

Rather than provide a review of the book as a whole, I'm going to focus on a few chapters and describe what I thought worked and what I thought didn't work. I chose chapters where I thought the author really had an opportunity to distinguish this book from other similar books. At the end of the chapter reviews I provide an overview of the book.

Chapter 1: Java in Review
In this chapter the author sets the stage for the following chapters by providing an overview of the Java concepts that the reader is expected to be familiar with.

The Good:
Assertions are one of the things that a good software engineer should understand and use. It shows good judgement on the author's part to put them at the beginning of the book so the reader can benefit from the author's impressions. I also found his discussion of initialization to be insightful and interesting. I thought I had a pretty solid understanding of the subject but I was surprised to learn that a field can be initialized by what amounts to an inline method. The author cautions that this technique shouldn't be used often, but he gives a compelling example of when it can be used. It's definitely a trick I'm going to keep in my toolkit.

The Bad:
The first problem is that none of the material in this chapter is necessary for understanding the other parts of the book. Most of it could be reduced to footnotes or sidebars if the author felt it necessary to clarify subsequent topics, but to spend time explaining the importance of the default clause in a conditional is a waste of the reader's time. There's an old saying, "Tell me and I'll forget, show me and I may remember, involve me and I'll understand." The author of a technical book needs to make a significant effort to involve the reader. If involving the reader isn't possible for some reason, the author should, at the very least, show the reader rather than simply enumerating principles divorced from a learning context. Simmons should show us how to use assertions by using them. He does a great job of this with his ubiquitious use of final. I'm less certain of how well he does with his other core concepts. I could go back to the book and look it up, but if I need to do that, it means he's already failed.

The other problem with this chapter is that the author assumes the stance that the reader is a C++ programmer approaching Java. He asserts, "To understand the advanced concepts of the Java language, there are a few core concepts that you must have firmly in mind. Without these concepts, much of this book will not make a lot of sense. The concepts of pointers in Java, its class hierarchy, and RTTI (runtime type identification) are three of the most important on this list." This list might be important for a C or C++ programmer moving to Java (which is a position I'll hazard a guess that the author found himself) but it's marginally useful for anyone else. Allow me to summarize: Java has no pointers, all objects inherit from java.lang.Object, and you can interrogate an object to determine its type at runtime. 'Nuff said.

Unfortunately, this is a theme that runs throughout the book. The author seems to assume that his audience has a C++ background and he either differentiates between the things that Java has that C++ doesn't (e.g., pointers) or he introduces bits from his C++ background that are also in Java (e.g., the ternary operator). The reason for this, I believe, is that the author has failed to separate himself sufficiently from his audience. That's to say, he's writing the book that he would have liked to have read when he was starting his Java career. This isn't a bad thing if you're sufficiently like Robert Simmons, Jr. to warrant that kind of advice, but if you're not, his exposition is going to be hit or miss.

Chapter 5: Exceptional Code
This chapter covers the use and misuse of exceptions in Java. It provides a summary of the different types of exceptions and provides some guidelines for good coding practices.

The Good:
Exceptions are an important part of Java and are misunderstood by a fair chunk of Java developers. The author recognizes this and attempts to provide an introduction to exceptions and show some of the common exception anti-idioms. His discussion on the necessity of the atomicity of transactions was valuable and clear. He shows what happens in the rare instances when a transaction fails midstream and isn't rolled back. He then provides good advice on how to write code to prevent this sort of thing from happening.

The Bad:
This is a short chapter and that's unfortunate because the topic of exceptions is rich and worth much investigation. This chapter provided an excellent opportunity for Simmons to display some virtuosity and say something significant about the subject. If nothing else, he could have elaborated on the relative merits of checked exceptions vs. unchecked exceptions; a topic that has been the subject of Holy Wars in the Java/C# community. Unfortunately, all he really mustered was an, "unchecked exceptions are Java's way of not cluttering up your code with too many 'throws' clauses." (paraphrased, but see the end of section 5.1.1)

The author seems to have some good intuitions around the use and misuse of exceptions, but rather than clearly delineating the issues and sharing his insight with the reader, he sets up a couple of toy examples that show the syntax of exception handling and waffles around the issue of when to use checked exceptions and when to use unchecked exceptions. There is little enough spoken about exception handling that this might be sufficient if Joshua Bloch hadn't already provided a solid grounding in exceptions with Effective Java. But since he has, I had hoped for some new insights, which Simmons failed to provide.

Chapters 9 & 10: Practical Reflection and Proxies
These chapters provide an introduction to Java's capabilities for introspection of types and objects, as well as describing the new JDK 1.4 DynamicProxy class. Simmons also gives some examples of how to write proxies--dynamic and static.

The Good:
In choosing to cover Java's introspection facilities, the author demonstrates that he recognizes the importance of metaprogramming as a qualification of Java expertise. It's on par with things like writing classloaders or grokking bytecode and it separates the gurus from the merely competent. If nothing else, it gives Java programmers the opportunity to do the things that smug lisp weenies are always nattering on about.

The author gives a good overview of how reflection works in Java as well as providing some examples. He also distinguishes between static proxies (like the Proxy pattern in Design Patterns) and the nifty dynamic proxy part of JDK 1.4 and shows how to use these proxies and provides some demonstrations of how they can be used.

The Bad:
As with much of the book, the examples aren't particularly compelling and Simmons doesn't take the opportunity to take the reader to the next level and show him some sweet metaprogramming. Reflection and proxies aren't complicated conceptually, and the syntax is fairly straightforward. He could have gotten the implementation details out of the way and then provided examples from the field. The JMock guys are doing some nice work in generating mock objects for unit testing with dynamic proxy and the Nanning guys have a nice aspect-oriented programming framework that uses reflection and proxies. This is the kind of work that's being done with metaprogramming and confining the discussion to toy examples is discouraging.

Overall:
The Good:
The author has a good conversational style and seems like the kind of guy that you'd enjoy working with--friendly, knowledgable, and genuinely enthusiastic about his subject. The book has plenty of interesting material. The use of final is a great way of turning logic errors into compiler errors. A knowledge of metaprogramming is becoming more important every day, and bringing metaprogramming to test-driven development is an idea with considerable merit. Someone new to Java could use this book as a sampler of some important ideas in the practice of Java programming and explore the topics in greater depth at a later point.

The Bad:
This book suffers because the author identified his audience and stated his goal and then didn't follow the path he laid out. As a result, the author winds up disappointing all readers. The novice will find that the author glosses over topics that are clearly over their heads, while the expert will be bored by the level of detail that the author devotes to relatively simple topics.

Additionally, the examples are so simple that a newcomer to Java will not have trouble following them, but someone who has used Java for more than half-a-dozen months will find them uninteresting and unchallenging. The author should have taken the opportunity to really explore the space.

Conclusion:
While this book covered some interesting and high level java topics, it covered them shallowly and its content was presented inconsistently to readers of varying levels of expertise. The author needed to stick with his audience, choose topics that fit well together, and challenge the reader. That said, I don't lay the blame entirely on the author. His editor should have made the book tighter, more compelling, and more focused on its central thesis: helping intermediate Java programmers become expert Java programmers. The technical reviewers, who are presumably experts, should have provided the feedback that Simmons needed to raise the bar.

The book would be more appropriately titled, Robert Simmons, Jr. Shares Some Cool Things from Projects He Has Worked On. I think the best thing for this book would have been for the author to cull each chapter down to one quarter of its existing size and then publish them separately as magazine articles.

Alternate Sources:
The Java Programming Language, 3ed and Effective Java together cover nearly everything in this book in much greater detail and with better authority. Ken Arnold and James Gosling are two of three authors for the first book, and Joshua Bloch, author of the java.util.Collections classes is the author of the second. If you've mastered the material in these two books, you're an expert, full stop. Unfortunately, these books don't really cover reflection and proxies. If you're an intermediate java programmer and you want a good overview of proxies and metaprogramming in Java, I recommend the source code for Nanning, a lightweight aspect-oriented programming framework for Java.

Alex Garrett is a contract programmer who mostly works with Java. For a while, he was the acquisitions editor for Manning Publications, which inclines him to be a smug publishing weenie. You can purchase Hardcore Java from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page.

11 of 197 comments (clear)

  1. Re:I've seen this before by NanoGator · · Score: 2, Interesting

    "It was in an ad for Starbucks."

    Ugh. Something Janet Jackson said a couple of years ago twisted my perception of what this ad was about. To those who don't get the reference, consider yourself lucky, and don't search for Janet Jackson coffee.

    --
    "Derp de derp."
  2. Re:assembly language is for pansies by I_Love_Pocky! · · Score: 4, Interesting

    Nothing could be easier to understand than finite state machines. The only trick is that you can't do as much with them. It doesn't make them hardcore.

    That is like saying hardcore is writing an english novel using only one vowel. There are a lot of novels you couldn't write that way.

  3. OT: Java performance on AMD64? by Anonymous Coward · · Score: 2, Interesting

    I see Sun have released Java runtimes for AMD64, and wonder what the performance is like compared to plain 32-bit intel, MHz for MHz.

    There should be a decent improvement running in 64-bit mode, both for the VM and the code it's running, or?

  4. Effective Java by ChiralSoftware · · Score: 5, Interesting
    by Joshua Bloch is the best programming book I have ever read in any language. It goes into detail about exceptions and how to use them properly. It sounds like it covers everything which this book covers, but it's brilliant. It's also a thin book. It is the only computer science book I have ever read multiple times, and gotten something out of it every time I have read it. Anyone else who has read this book is invited to chime in here...

    -----------
    WAP software

  5. Hardcore Java by herwin · · Score: 2, Interesting

    I bought the book hoping for material that I could present in an Advanced Object Oriented Design class. I was disappointed.

  6. Hardcore French (and English) by Anonymous Coward · · Score: 1, Interesting

    On the topic of writing books using only one letter, there have been a few books written without the use of one letter: the letter E. Among others, La Disparition, a French novel by Georges Perec, is E-less. This book, remarkably, has been translated (by Gilbert Adair) into English. The translation, titled A Void, also E-less. Now that's hardcore.

  7. Re:Hardcore? Or dumb? by spankalee · · Score: 2, Interesting

    Well... I didn't say they were smart ideas, but hardcore has never meant prudent to me.

    Also, using assembly means you're just begging for a maintenance headache as well.

    It's all in why you're doing what you're doing. For some stuff you might need to get hardcore (oooh, how extreme :)

    When I was writing applets back in the 1.0 days I had to do some crazy hacks to get around Microsoft incompatibilities, or to implement double buffering or transparent widgets. Some of the hacks included changing Sun's source, recompiling and using bugs in the security manager of Netscape and IE to load new AWT base classes. Not very smart you might say, and certainly not very maintainable, but it worked, and when 1.1 came out I didn't need my hacks anymore.

    Some of JDO's techniques wouldn't be possible if it weren't for binary class enhancers. The class file format is very well documents and can handle metadata for fields and methods. JDO adds metadata to the class that enables OR mappings, and lets you use managed object just like any other.

    And, as a matter of fact, you can count on the format of the class file to be the same regardless of the compiler. It's a specified format.

  8. Re:Hardcore Quiche by Nefarious+Wheel · · Score: 2, Interesting

    My old departed friend and LGP-30 programmer once caught Cray filing down a resistor before soldering it back into the discrete circuitry. Something about tuning a pipeline cascade. Cray pretty much invented the instruction pipeline, and was known for tweaking his designs personally.

    --
    Do not mock my vision of impractical footwear
  9. Re:The author has some articles on nested classes. by tcopeland · · Score: 2, Interesting
    > definition of mainstream

    Hm, maybe. I don't know. They look cluttered to me, especially in a language where blocks aren't the done thing. In Ruby, it's common to see blocks being invoked:
    some_array.each {|x| put x }
    but to see an anonymous inner class created in Java looks sort-of-blockish-but-not-really.

    > keep the event handling code
    > close to the control code.

    I don't know. Almost every time I make an anonymous inner class for a JButton I end up extracting it to a nested class so I can also use it for a JMenuItem. But, to each his own...
  10. What about "Hardcore Visual Basic"? by 1iar_parad0x · · Score: 2, Interesting

    A counterexample

    Mock me if you will, but there was once a book called Hardcore Visual Basic. It was one of the few intelligent books written on the subject. I'm not a big VB fan, but I can appreciate how it once was a great RAD tool. I wished all of Microsoft's VB-like documentation looked like this. It was rigorous and concise.

    I remember all of the laughs I got when I went around the office asking if anyone had ever heard of a VB book written for C++ programmers. Of course, my smart-ass smirk probably didn't help. Ironically, I found out that a good dose of the Win32 API in C++ and a 20-minute tutorial from a fellow colleague would have probably been the best route. Still, half of VB's problem is Microsoft's overall tendency to suck the brain out of the developer's head. While this might be okay for an end-user, I can't recommend doing this to developers.

    "It was the best of times; it was the worst of times."

    Like everything else in life, there's nothing wrong with bragging if you can do it. Sure, we mock such cliché verbiage, like the line above. Dickens' can pull off such an overdramatic line. I can't. I can't make a 1000 page tome interesting. Tolstoy could. So, if a book is hardcore, let it be. If it isn't, it will make a mockery of itself.

    The cruel irony

    Apparently the author got so sick of Microsoft ruining a perfectly good thing, he decided to stop coding VB altogether. You can see a copy of his vented frustrations here. His fellow VB coders mocked him for trying to get a language to do more than it was supposed to. If that ain't hardcore, I don't know what is. I think he's writing Java code now.

    --
    What do you mean my sig is repetitive? What do you mean my sig is repetitive? What do you mean....
  11. Re:Hardcore? Or dumb? by Doomdark · · Score: 2, Interesting
    Uh? Where did he say "hardcore" equals "the right way"? I definitely think examples he mentions are pretty hard-core, as in doing things most developers aren't even aware can be done, and wouldn't dream of doing.

    My personal favourite of hard-core java things, though, is replacing default Object class that comes with JDK with your own. It was presented in the best java performance tuning available, and was rather interesting thing to do. Author just added bit more debugging, and overriding things in Object may be useful for that... you can be sure you get to debug ALL constructors your app ever invokes, even system classes' constructors.

    And I'm not saying replacing java.lang.Object is a generally useful practice, or even too smart, most of the time. Yet it's definitely hard core.

    --
    I like paying taxes. With them I buy civilization -- Oliver Wendell Holmes