Books & Tools Techniques

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

Jude

Jude is my Java documentation browser. It combines Sun's definitive javadocs with the easy-to-use format of Java in a Nutshell, and tops it off with easy keyboard-based navigation and full-text searching.

Jude is available for free evaluation.

See the user's guide for more info

Java in a Nutshell

The 5th edition is now out, with complete coverage of Java 5.0!

It includes a fast-paced tutorial on the language, and a compact quick-reference for the core Java API.

Java Examples in a Nutshell

The 3rd edition, updated for Java 1.4

This edition has all-new coverage of the NIO and JavaSound APIs, completely rewritten Servlets and XML chapters, and coverage of new Java 1.4 features (assertions, logging, preferences, SSL, etc.) added througout. A great book for those who like to learn by example. 193 working examples: 21,900 lines of carefully commented code to learn from.

Java 1.5 Tiger: A Developer's Notebook

Amazon incorrectly credits me as the main author on this book. I'm actually the second author: really more of a consultant. This is a good book about all the language changes in the latest version of Java.

Effective Java

I didn't write this excellent book, but I wish I had.

Author Josh Bloch is probably best known for the collections classes in the java.util package. His experience and wisdom are apparent in this book. I learned from it and recommend it highly.

March 16, 2004

What does the word "generic" promise?

Bruce Eckel, author of Thinking in Java has a controversial blog entry about generic types in Java 1.5.

I believe that Bruce has largely missed the point of Java's generics, and that the "latent typing" ideas he discusses would take Java in a very unJava-like direction. His post turns into something of a rant, but the crux of it seems to be this:

I feel lied to (by the term generic)

Basically, Bruce had heard about generics in Java 1.5, but had not yet read about them. The use of the word "generic" gave him a very mistaken idea about what this language feature actually entails. And then when he actually sat down to study generics in Java he was sorely disappointed.

I don't want to debate Bruce's other points here. I am curious, however, whether anyone shares Bruce's concern that the term "generic" when applied to Java's parmeterized types, promises something beyond what Java delivers. I haven't read Bruce's books, but he's presumably a pretty smart guy. If he's gotten this confused by the use of the word, I wonder whether others share his confusion. If the term "generic" is confusing, I'll want to avoid it in the next edition of Java in a Nutshell, or at least include a footnote about the potential confusion.

If you're familiar with generics in Java 1.5, and have used a similar facility in another language, your comments are encouraged!

March 07, 2004

Java 1.5 Enum Line Noise

Tim Peierls, a colleague on the JSR-201 expert group, shared the following Java enumerated type declaration with me. He described it as "line noise":

enum _{_,;;}    

(Remember line noise? I think it has been a decade since I last used uucp or had to manually debug a ppp connection by sending atdt to the modem, so I don't see much line noise these days...)

Tim's examples always seem insightful or instructive. This is one of them, and it highlights a couple of important points about the syntax of enum declarations. So let's take this declaration a token at a time.

  • enum: obviously, this is the keyword, like class or interface, that is used to declare an enum.
  • _: The name of the enumerated type is just underscore. This is a silly thing to do, but it does make it look more like line noise.
  • {: the body of an enumerated type is enclosed in curly braces, just as a class is.
  • _: the second underscore is the name of the single value of this enumerated type. Again, this is silly, but legal, name, chosen to make the example amusing. Having a type and member both named underscore leads us to code like System.out.println(_._); which looks more like Morse code than Java!
  • ,: the enum syntax requires a comma between the names of enumerated values, and allows a comma following the last one. Tim put this optional comma here to highlight this fact. (Tim and I both believe that this optional comma is a good thing, by the way: if you use it, it is easier to rearrange the order of constants or add new ones to the list without ending up with a missing comma.)
  • ;: the semicolon separates the list of enumerated values from the optional class body of the enumerated type.
  • ;: this second semicolon is an empty member declaration within the class body. I can't explain why empty members declarations are allowed, but I can site section 8.1.5 of the Java Language Specification. You can actually put any number of semicolons here.
  • }: this is the closing curly brace that ends the type.

It is the optional bits of syntax that Tim has highlighted with this example. If we strip it down to just the required tokens, we're just left with an example that is not nearly as interesting:

enum _{_}

If you want to try it out yourself, here's the test program I wrote around Tim's enum:

public class linenoise {
    enum _{_,;;}

    public static void main(String[] args) {
	System.out.println(_._);
    }
}

Finally, Tim leaves us with an exercise for the reader:

enum _{_,;;}      // if this were an emoticon, what would it mean? 

If you have an answer, feel free to leave a comment.

March 01, 2004

Updated Examples from Java Examples in a Nutshell

If you're a reader of my book Java Examples in a Nutshell, and have previously downloaded the examples from this site, you may want to grab them again from http://www.davidflanagan.com/javaexamples3. A few of the examples require auxilliary properties files, which I forgot to include originally. Thanks to Ronald Tosh for pointing this out. The new .tar.gz and .zip archives contain the required properties files.

Advertising
About
Store
Search
Google
Web this site
Archives
Syndicate

Powered by
Movable Type