Feel of Java Revisited

On February 28, James Gosling gave a presentation in Sun's Santa Clara Campus auditorium (formerly a part of the Agnews Insane Asylum :-)), entitled “Feel of Java Revisited”. The talk promised to revisit the classic Feel of Java paper that famously declared “Java is a blue collar language”. (SJSU students: Go here for free access to the paper.)

I teach a graduate class in programming languages at San Jose State University. Instead of covering denotational semantics or logic programming, I decided to cover what is hot in dzone (closures, metaobject protocols, etc.) and smuggle in the theory under the radar. My class has been learning about the various closure proposals for Java, and we played with the BGGA and CICE implementations in the labs. (If you want to play along, go here for a guest login. Sorry, no FCM yet. The implementation came after I designed the lab.)

Aaron Houston, the tireless champion of the Java Champions, got my class tickets for the event, with reserved seating, free T-shirts and a Sun Spot kit for the CS club. Thanks Aaron!!! We all had an amazing time.

Much to my disappointment, the presentation did not engage in mudslinging about competing closures proposals :-) Instead, James revisited his personal journey to Java. It was very interesting to see how his experience with prior scripting languages and compiler projects shaped his thinking. When Java was created, the “blue collar” language was C. Used by Real Programmers who were manly enough to spend weeks tracking down obscure memory corruption errors. Garbage collectors were used by quiche eaters. James explained his goal of combining a familiar syntax with the features that are required for security and reliability. He also recounted his many years of experience with virtual machines, from industrial and academic projects. It became apparent how Java—the happy marriage of blue collar and quiche eater programming—was no accident but the result of a careful design process.

Of course, closures came up in the Q&A. James said that he personally loves closures and would like to use them in Java if and when they become a part of it. (There had been some speculation in the blogoshpere whether closures fail the “blue collar test”, which James refuted in this blog.) I asked about the decision process that governs the evolution of the Java language. In response, James grumbled a bit about issues with the JCP process. James made it clear that he considers generics a great win, despite some of the ugly corner cases. Kirk Pepperdine asked about Java FX and whether it was competitive with Flex and Silverlight. James gamely said that it will be an interesting battle. There was some discussion about the successor of Java, and James said that the JVM is more important than Java itself.

This all left me thinking about closures and blue collar programmers. 15 years ago, only the super-rich had a plasma TV, and only eggheads used a garbage collector. Now, flat screen TVs are everywhere, and I can't think of a recent programming language that doesn't have garbage collection. Time marches on, and what was once a luxury becomes commonplace in blue collar households.

Consider this example from my homework assignment. Instead of this mess of code, use BGGA closures to put work on a background thread or the event dispatch thread like this.

            Scanner in = new Scanner(new FileInputStream(file));
            onBackgroundThread()
            {
               int lineNumber = 0;
               while (in.hasNextLine())
               {
                  String line = in.nextLine();
                  lineNumber++;
                  onEDT()
                  {
                     statusLine.setText("" + lineNumber);
                     textArea.append(line);
                     textArea.append("\n");
                  }
               }
               onEDT()
               {
                  openButton.setEnabled(true);
               }
            }

Note how much clearer the code has become. Put time-consuming work on the background thread, and put the UI update on the EDT. Java FX needs special keywords, for this. With closures, you just define a couple of utility functions. It is so easy that one of my students wrote:

Last time, it took me at least 10 hours to do one of the problem, but i got through #1 in less than 1/2 an hour. most of it was copy and paste. I didn't even need more than 1 class. am i missing something? It's almost as if you can lift the solution out of the labs. All I had to do was write 2 really really really simple closures.

It doesn't get more blue collar than that :-)