JavaOne 2008, Day 2

On Day One, I picked Josh Bloch's brain for a bit about whether the BGGA closures proposal was redeemable if the gnarlier bits might be removed, leaving it basically with function types.  It was cool to mingle with the Java "rock stars", if only for a moment.

I enjoyed Neal Gafter's Day Two talk "Closures Cookbook" immensely.  He gave a very clear exposition of the BGGA proposal and the use cases propelling it.

Right out of the gate, he started with a disclaimer: Google is open to multiple parallel investigations of closures but is not currently prepared to commit to any particular proposal.

The cool bit is that closure literals can be used as instances of one-method interface types whose method parms and return type are compatible with those of the closure:


    Runnable r = { => doWhatever(); }
    r.run();

    Callable<String> cs = { => "result"; }

    Comparator<String> reverse = { String s1, String s2 => s2.compareTo(s1); }

    ItemSelectable is = ...;
    is.addItemListener( { ItemEvent ev => doSomething(ev, is); } );

Apparently there are technical reasons why this couldn't be done for abstract classes with one abstract method, didn't quite get the picture...

Also considered were aggregrate operations,  near and dear to my heart:


double highestGPA = Double.MIN_VALUE;
for (Student s: students) {
  if ( s.graduationYear == THIS_YEAR ) {
     int gpa = s.getGPA();
     if ( highestGPA < gpa )
       highestGPA = gpa;
  }
}

double highestGPA =
    students.filter( { Student s => s.graduationYear == THIS_YEAR } )
            .map( { Student s => s.getGPA(); } )
            .max();

I just love how the second reads -- nothing like method names to make intent clearer.

An extended example involving an API for timing units of code:


interface Block<R, throws X> {
    R execute() throws X;
}

public <R, throws X> R time(String opName, Block<R, X> block) throws X {
  long startTime = System.nanoTime();
  boolean success = true;
  try {
    return block.execute();
  }
  catch (final Throwable ex) {
    success = false;
    throw ex;
  }
  finally {
    recordTiming(opName, System.nanoTime() - startTime, success);
  }
}

int f() {
  time( "opName", { => someStatements } );
  time( "opName", { => return computeResult; } )
}

Yowza.  Nice how it genericizes over whatever exceptions the block may raise (including none), and whatever the block might return (including nothing).  Note the use of "safe re-throw" by marking a catch parameter final (proposed for JDK7).

Alex Buckley and Stanley Ho gave a nice summary of the first-class language and tooling support for modularity in Java (JSR 277).  Seems a JAM module would be able to leverage OSGi bundles and repositories?  Nice.

The Java Persistence API 2.0 talk was packed.  Ridiculously packed.  Fire marshal, anyone?  People continued to stream in well into the presentation.  One guy ended up accidentally kicking separating my MacBook power supply from the pluggable portion of it.  Not so much as a "sorry, my bad" -- never looked back.  I understand there's a certain amount of Asperger-style intense focus at a geeky conference, but come on.  Sorry if I seemed a bit peevish, but several hot buttons were hit in this one: overcrowded room, disregard for personal space, cell phones ringing after several admonishments to silence them, relatively shrill speaker a bit trigger-happy on the slide flipper ... I guess my bitching about it was way more annoying to the guy in front of me, as when I uttered the line, "As a courtesy to others, please silence your cell phones", he shot back with the timeless classic, "Why don't you silence yourself, dude?"  Cue the slow clap.

Anyway, I didn't get that much out of the JPA talk.  I'm not doing much RDBMS work these days, but at least I have a sense of where to look for JPA info.

I bailed out of the talk "Unit Testing DB Operations with DBUnit" a shade early to catch a power nap -- I had no idea how exhausted I'd be after 1.5 days at the conference.  That said, I scheduled a number of sessions and BOFs -- perhaps next time I'll pace myself a bit better.  Besides, I've used DBUnit before, and it it quite nice -- not much new ground covered for me.

"Boldly Go Where the Java Programming Language Has Never Gone Before" -- Geert Bevin's talk's premise was that "You don't have to master new languages, tools, or libraries to deliver applications that go much further than what the standard Java platform provides."  He gave compelling demonstrations of Terracotta, an OSS clustering solution for the Java platform; RIFE, a component-based web framework featuring continuations; GWT; and Google Android.  Very nice stuff!

"Building RESTful Clients with JavaScript, Ruby, and JavaFX" -- not much here you couldn't get from an introductory article on REST.

Ola Bini of ThoughtWorks gave a talk about TW's use of JRuby.  As an ex-ThoughtWorker I was eager to hear about what TW's been up to in the Ruby world -- clearly, quite a lot.  I left TW just as it was beginning to pursue and land Ruby/Rails work.  Right now, 40% of its US revenue comes form Ruby/Rails work.  Surprising to learn that test suites run more slowly often in JRuby than in MRI -- less opportunity for JIT leverage, it seems.  Often they run test suites in MRI pre-commit, then with JRuby in CI build.

"Cooking Your Own Groovy Builder: A Step Forward into Domain-Specific Languages" -- nice exposition of the Builder support for languages that describe hierarchical structures such as XML documents and Swing widgetry.

Written on May 8, 2008