Showing posts with label JavaOne 2012. Show all posts
Showing posts with label JavaOne 2012. Show all posts

Saturday, October 6, 2012

JavaOne 2012: Observations and Impressions

I am starting this particular blog post as I sit the the San Francisco International Airport waiting to board an airplane to head home after another satisfying but tiring JavaOne (2012) experience. It is difficult to write another blog post after having frantically written ~30 blog posts on the conference since the keynotes on last Sunday, but I want to record some of my observations and impressions of the conference while they're still relatively fresh. More than in previous years, I did embed some general observations (usually complaints) within posts on individual sessions.

This post is broken up into "the good," "the bad," and "the ugly" of JavaOne 2012. I want to emphasize that the conference overall was outstanding and I am appreciative of the opportunity to have attended. I hope the overall tone of my post reflects my overall highly positive feelings about this conference, but also presents a realistic portrait of the not-so-great aspects of the conference.

The Good

Overall Technical Content

There is a wide variety of things conference attendees look forward to in a conference. Many of us look forward to many of the same things in a conference. For me, the single most important attribute of a technical conference is its content. In that category, JavaOne 2012 was a success. There was actually too much good content to take it all in, but that's a welcome dilemma.

High Attention to Low-Level Details

I think Adam Bien made an important observation: even though it's nice to have community involvement in the conference, JavaOne presents a special opportunity to hear from the folks (mostly Oracle employees) working "in the trenches" on the latest Java APIs, specifications, and SDKs. Bien put it this way, "I mainly attended sessions delivered by Oracle engineers. 90% of this sessions were great with unique, deep technical content probably only deliverable by someone implementing the low level stuff. This is my personal motivation for attending JavaOne."

I've been to database-oriented conferences where many of the Oracle employees' presentations are heavy on marketing and slideware and low on technical detail. That's not the case at JavaOne where Oracle employees present the low-level details that Java developers want to hear.

Breadth and Scope of Technical Content

No matter in which dimension it is measured, JavaOne 2012 featured breadth and depth of content. Subjects in Java SE, Java EE, Java ME/embedded, web, JVM (alternate languages), and even some non-Java topics were available in nearly every session block. The keynotes (especially the Strategy Keynote and Technical Keynote) and select presentations that I attended provided roadmaps and vision for what lies ahead.

I enjoyed the breadth of "temporal usefulness" available in the presentations. I learned about things I like won't use anytime soon but are interesting and mind-expanding (Ceylon, JavaFX Embedded, Play Framework, Akka, Tiggzi), things that I'll definitely use in the intermediate future (Project Lambda, JSR 310 Date/Time API), things I'll use in the near future (Scala), and things I'll use almost as soon as I get home (JDK 7's jcmd, NetBeans Project Easel, Checker Framework). I was even able to learn several new tips and/or tricks for things for which I already had significant familiarity (Groovy, JavaFX, NetBeans's custom declarative language for refactoring/hints).

Attention to Community

I stated above that I agree with Adam Bien's assertion that one of the most valuable aspects of JavaOne is the access to people working directly on the future of Java. That being stated, I do appreciate Oracle making a real effort to reach out to the community. I posted during several presentations in which the speakers solicited feedback and ideas from the community and the audience. This was a nearly universal theme of any of the presentations related to anything open source. The JavaOne Community Keynote is the most obvious manifestation of JavaOne's commitment to community, but that theme was reiterated in numerous presentations.

The Host City

San Francisco is a great city to visit and offers lots to do for downtime and for people traveling with JavaOne participants who are not themselves attending JavaOne. Although I look forward to any opportunity I get to attend JavaOne, I think I look forward to the visit to San Francisco as much as the conference. It's definitely an interesting city to visit with great dining and other activities. The weather was pleasant and clear most of the time, though fog rolled in occasionally to remind us it is San Francisco and it was unusually hot in the early portion of the conference.

Oracle makes the presence of Oracle OpenWorld and JavaOne well-known throughout the city. Taxicabs feature signs for the respective conferences on their advertisements, there are signs all over the place, and some sections of the downtown near the conference venues (Moscone for Oracle OpenWorld and three Union Square hotels for JavaOne) for activities.

Extracurricular Activities

JavaOne provides numerous extracurricular activities beyond the technical content of the conference and beyond what the city provides. I didn't participate in many of these this year due to other commitments and activities, but the offerings are fairly impressive. The Oracle Appreciation Night, which featured Pearl Jam and Kings of Leon this year, is especially impressive. Although there are numerous disadvantages to JavaOne being the "little brother" held simultaneously with Oracle OpenWorld, some of these activities are available because of the bigger and better attended big brother conference being held simultaneously.

The Return of James Gosling

There was no denying that the "surprise" return of James Gosling to JavaOne (Community Keynote) left a big and very positive impression. The nostalgic factor (reminder of JavaOne's most glorious days) seemed to be as big as Gosling's presentation itself. I monitored a lot of the Twitter traffic during the week on "javaone" and no single Tweet or set of Tweets came anywhere close to being tweeted and re-treeted as often as mention of Gosling's return to JavaOne.

Increased Exposure to Tools

Master craftsmen in any industry are more successful with the correct tools. At JavaOne 2012, I became familiar with tools that I either had not been aware of previously or had not fully appreciated previously. These were either the subject of the presentations I saw or were used "incidentally" during projects and hallways discussions. These projects included JaCoCo Java Code Coverage Library (first read about in a Tweet), Checker Framework, the Oracle JDK 7 jcmd command-line tool, and NetBeans 7.3 Project Easel. I was also reminded that JDeveloper provides one of the better free UML tools, an important reminder now that NetBeans no longer supports UML (UML last supported in NetBeans 6.7).

Online JavaOne 2012 Coverage

Modern technology continues to make JavaOne more accessible to developer worldwide each year. Oracle made a lot of content available online early in the conference and individual members of the community also contributed significantly to the JavaOne coverage. Even some of the individual contributions were in part due to Oracle; I, for example, attended JavaOne 2012 on a blogger pass and was able to write posts like this one thanks to that complimentary pass. Between attending sessions, visiting some San Francisco sites, and writing my own blog posts, I've only been able to read a fraction of the other posts written about JavaOne 2012. I hope to catch up on those in coming weeks. I did try to watch Tweeted messages about the conference as it went along and was impressed with the quick coverage of important aspects of the conference.

Oracle has made "featured keynotes and highlights" available online (video). There have been several Oracle-originated blogs of interest including Oracle Outlines Roadmap for Java SE and JavaFX at JavaOne 2012, Virtual Collateral Rack (PDFs of sessions), Thursday Community Keynote: 'By the Community, For the Community', JavaOne 2012 Sunday Strategy Keynote, and The JavaOne 2012 Sunday Technical Keynote.

Individual JavaOne 2012 summaries include Jim Gough's Highlights From Java One 2012, Mark Stephens's 5 key things I learnt at Javaone2012, Yakov Fain's My Three Days at JavaOne 2012, and Trisha Gee's JavaOne: The Summary.

A Dose of Reality

The blogosphere tends to distort the reality of software development for a variety of reasons (dominated by "new" and "interesting" developments, for one). Attending conferences can be a good way to talk to others to get a better perspective on the reality of general software development. For example, at JavaOne 2012, there were several reminders that there is still significant software development that occurs on the desktop (it's not all web/mobile) and that the demise of UML has been overstated.

The Bad

These "bad" things are mostly accepted parts of the JavaOne experience. They are certainly outweighed by the good both in terms of number of "bad" or "good" things and in terms of importance of the things. In other words, there were more good things about JavaOne and the good things were more important to me than the bad things.

The Hotels Venue

The spreading of JavaOne over three Union Square hotels (Hilton, Parc 55, and Nikko) and the Masonic Auditorium would probably not be as big of a negative if JavaOne attendees were not aware of the presentations-friendly Moscone Center in the same city just blocks away. I am getting used to this venue and can navigate it better now than previously. I actually often enjoy the opportunity of going outside to move between buildings. However, I also found myself changing a couple selected presentations in the last couple of days because my original choice was in a particularly poor conference room area.

Poor Wifi

The Wifi at JavaOne simply cannot scale to the number of people wanting to use it via laptops, iPads, iPod Touch devices, Android tablets, and other personal devices. The Wifi was pretty good in the mornings before things got going and was outstanding on Thursday afternoon when a lot of people had already left.

The Food

Like the venues, the food is not completely awful; it's just not very good. It is sufficient for what is needed (providing nutrients and energy), but its lack of flavor stands in stark contrast to the excellent breakfasts and dinners I enjoyed again this year while in San Francisco.

Getting To and Leaving San Francisco

My flights into and out of San Francisco were both delayed due to fog in San Francisco and/or due to metering of traffic in the airport. In addition to this, we were told that the U.S. Navy's use on SFO for some of their Fleet Week exercises was the reason we sat on the runway for an extra twenty minutes. This is an example of where the good (being in San Francisco for the conference) outweighed the bad.

The Ugly

Inconsiderate and Intentionally Rude Misbehavior

Perhaps the ugliest part of JavaOne 2012 had little to do with the conference itself or its organizers, but was instead caused by a small portion of its attendees. It seemed that I repeatedly got behind the person trying to text and walk at the same time. These individuals slowed down traffic in the already congested halls as they walked more slowly and wandered in unpredictable directions and caused people to try to walk around them, causing additional issues. People tend not to drive and text as well as they might think and walking and texting is no different. The walking while texting may be less dangerous than driving while texting, but it's not without its dangers. There was one guy I was behind who was stopping intermittently while trying to eat and walk down the stairs because he was losing his lunch or snack. Continuing to try to do both made it so that neither was done well.

Other misbehavior that I observed were observed by others as well. These included unnecessary presentation hijacking, mobile phones ringing in sessions and some people even taking the call without leaving, people cutting in lines, and excessive entering and exiting of presentations at mid-point (most noticeably a problem when someone who sat in the first few rows made a show of his or her exit). The majority of attendees were well-behaved, but the small fraction of inconsiderate and even intentionally rude attendees was probably the ugliest part of JavaOne 2012. In defense of JavaOne, this "ugliness" seems to be more reflective of human behavior than of the conference.

Additional / Miscellaneous Observations

Trendy Topics

Some of the topics that seemed particular popular at this year's JavaOne included REST, HTML5, Project Nashorn, JDK8/Lambda, NetBeans, and Embedded/Raspberry Pi.

Convergence

A major theme of JavaOne 2012 was "convergence." This theme was explicitly identified in the keynotes and several presentations such as "Looking into the JVM Crystal Ball" (convergence of Oracle's JRockit and HotSpot JVMs), "Mastering Java Deployment" (convergence of Java SE and JavaFX), "JavaFX on Smart Embedded Devices" (convergence of JavaFX and JavaFX Embedded, representing convergence of editions of Java [EE, SE, ME]), "NetBeans.Next - The Roadmap Ahead" (sharing of features between NetBeans and JDeveloper), and "Diagnosing Your Application on the JVM" (convergence of VM tools between JRockit and HotSpot and converge of command-line tools into single new jcmd tool).

One of the manifestations of this convergence of versions of Java is the renaming of versions. It was interesting to hear multiple speakers refer to current JavaFX as JavaFX 2.2 and the "next" major version of JavaFX as JavaFX 8 (version that was to be called JavaFX 3). This version naming change is documented in the post JavaFX 2.2 is here, and JavaFX 8.0 is on its way! Similarly, Java ME is seeing a version naming change as well: Java ME 3.2 is the current version and Java ME 8 is the "next" major version.

JDK 7 Update 10: The Next 'Big' Minor Release?

I heard multiple Oracle presenters mention features that they are already using in JDK 7 Update 10. Given that most of us who are using JDK 7 are using JDK 7 Update 6 (and JDK 7 Update 7 is the current regular download), it sounds to me like JDK 7 Update 10 may be the next "minor" release of JDK 7 with significant new tools for things such as application diagnosis and application deployment.

The naming of JDK minor releases with odd numbers for Critical Patch Updates (CPUs) and even numbers for "limited update releases" was announced previously. JDK 7u10 Build b10 is available in Developer Preview.

"Java" Becoming Bigger Than Ever

One thing that is clearer to me than ever before after attending JavaOne 2012 is that "Java" has become big for any one person to get his or her hands around the whole thing. Even some of the most knowledgeable experts I know in the Java community were heard to say that they would need to ask someone else to answer a specific question out of their area of expertise. It's becoming increasingly difficult for any one person to thoroughly understand all aspects of Java (JVM, EE, SE, ME, etc.). When you throw in alternate languages and new frameworks and tools, one person simply cannot learn or understand all of it. It's great that we have so many choices, but it can be frustrating to see entire areas of "Java" that would be interesting to delve into, but simply require too much time and effort to give it those areas the desired degree of attention.

Overall

Overall, I think JavaOne 2012 was a success by most peoples' measures. It certainly was by mine. I'm not the only one who was sorry to see it end.

JavaOne 2013 will be held September 22–26, 2013, in San Francisco.

Thursday, October 4, 2012

JavaOne 2012: Introduction to Ceylon

For my last session of JavaOne 2012, I elected to attend Emmanuel Bernard's and Stephane Epardaud's (both of RedHat) "Introduction to Ceylon" presentation held in Hilton Golden Gate 6/7/8.

It has become noticeably quieter in the Hilton since the ending of the morning's Community Keynote and especially since lunch. The Wiki is working great now (no more need to use my Verizon Broadband) and the Hilton's halls seem vacuous with so few people in them. This is typical of such conferences and I have mixed feelings about it: I like being able to more easily navigate the halls and enjoy the speedy Wifi, but there is an almost tangible drop in the energy level as well. It is also with some sadness that I think about this being the last session of the conference. On the other hand, I look forward to having some time to try out some of the things I've learned here and I look forward to seeing some of the presentations I missed here (the "opportunity cost" for attending other presentations).

The speakers stated that "Ceylon is not just vaporware" and said that they created it with the idea of creating a language that Java would be today if built from scratch but with the experience and lessons learned from using Java for many years. Ceylon was "initiated and led by Gavin King" with the intent to "improve upon frustrations of Java." They described Ceylon as a "powerful, readable, predictable" language which has a "platform, modularity, and tooling."

It was stated that Ceylon design highly prizes readability and may, if necessary, require a little more verbosity, rather than rely on tricks, to preserve readability. One of the goals is to make Ceylon very readable to Java and C-style language developers.

Slides with embedded color syntax highlighted code were shown to illustrate Ceylon code. Instead of private, public, and protected, Ceylon allows for either accessibility of shared ("public-ish") or else the default scope is scope-private. Another illustrated difference is that the Ceylon class did not need an explicit constructor. Ceylon provides "immutability by default." The assignment operator is reminiscent of Pascal with :=.

The illustrated example of inheritance looks similar to Java, but with more compact syntax. It was also pointed out that Ceylon has "very few keywords" and many of the items that appear to be keywords are really annotations. The string method is the Ceylon equivalent of Java's toString().

Ceylon does not allow method overloading because support of method overloading makes the compiler and other things more challenging. One common case for overloaded methods is optional parameters and Ceylon supports this via default parameters and named parameters. The second common use case for method overloading is to handle different (sub)types of parameters and Ceylon deals with that case via union types.

Ceylon allows a default implementation to be provided for an interface method with satisfies. This is not a "multiple inheritance mess" because there are no state initialization issues and an implementation must be provided if otherwise ambiguous. It was noted in the audience that this looks very similar to what Java 8 is bringing with interface default methods (brought in for Lambda to be merged into the SDK collections and other libraries).

Like languages such as Groovy and Scala, there are no primitive types in Ceylon (everything is an object, though Ceylon optimizes to primitives underneath the covers when appropriate) and so methods can be called directly on literal numbers. Ceylon also provides type inference. Although it appears to be dynamic, it is actually highly static.

Ceylon aims to avoid NullPointerExceptions encountered at the wrong time (is there a good time for NPEs?). Ceylon helps with this by forcing a question mark (?) the be appended on the end of the type of something that can be null. Once this is done, the Ceylon compiler enforces the variable of that type with the ? to be checked before accessed. Ceylon also has a Groovy-like null safety operator (?.).

Ceylon also supports functional programming. The speakers referenced JavaScript as the "biggest, most successful functional programming language." They showed code snippets using both FP-style closures and imperative-style comprehensions.

Ceylon supports a union type and an intersection type. A good reference on Ceylon types is available in Tour of Ceylon: Types.

Modularity is an important concept built into Ceylon. Packages belong to modules. In a dig on Jigsaw being moved to Java 9, it was noted that modularity was built into Ceylon from the start rather than "in 7, then in 8, then in 9."

The speakers introduced Ceylon Herd (Ceylon modules repository) and talked about the Ceylon Eclipse plugin.

The speakers addressed the Ceylon community. RedHat contributes and the community is encouraged to contribute. They use the "best tools" (github, ant, Eclipse, HTML5, Awestruct, Java, JavaScript, OpenShift, Play!) for contributing to the language. Their "To infinity..." slide stated that there are "five milestones to reach 1.0" with "some features targeted to 1.1." M1 is "done" (minimum all Java-style features and tools/IDE) as are M2 and M3. They expect M4 within weeks and M5 (Ceylon 1.1) is anticipated sometime after that. This is another presentation to add to the long list of presentations in which the speaker(s) requested the community to help them with their project.

One audience member was concerned about the theoretical formality of the Ceylon language. There is a Ceylon 1.0 Specification.

Ceylon supports extending Java classes and even depending on Java artifacts. Ceylon is a JVM-based language, but there is also effort to compile Ceylon to JavaScript.

The presenters stated that one should not use Ceylon for production yet (M5/Ceylon 1.0 has not been reached). However, now's a good time to play with Ceylon and report back any errors or negative features and help influence the language.

I liked a lot of what I saw about Ceylon, but it's still not clear to me why an entirely new language was necessary when many of Ceylon's advantages are common to other newer languages such as Groovy and Scala. There are some neat features to the language, but not enough "that's completely new" moments for me to leave more familiar languages. On the other hand, if I find myself with time on my hands and nothing interesting related to the languages I am already familiar with, playing with Ceylon could be an interesting hobby. However, if I have to choose between playing with and learning Scala and playing with and learning Ceylon, I'd have to favor Scala at this point.

I'd like to see a reason to use Ceylon compelling enough to justify using a language with a smaller community and less maturity rather than using another strongly typed language such as Scala or even rather than using an improving Java. A nerdy part of me really enjoys learning about new languages (hence my attendance last year at the presentation on Fantom and Gosu) and thinking about their assumptions, strengths, and weaknesses, but the more practical side of me likes to know the justification for learning a new language and ecosystem before investing much in that. This presentation allowed me to do the former (learn about a language new to me and give me some things to think about) while only costing me an hour of my time. It was an interesting well-spent hour that met my desire to be exposed to a new programming language.

JavaOne 2012: Getting Started with the NetBeans Platform

I stayed in the Hilton (Continental Ballroom 7/8/9) to see Geertjan Wielenga's (Oracle Development Tools Principal Project Manager) presentation "Getting Started with the NetBeans Platform." Geertjan's bio on his blog summarizes his involvement with NetBeans:

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Wielenga began his presentation by talking about how desktop-based graphical tools are underrepresented at conferences and pointed out that it's unlikely that flight controller software will be run out of a browser anytime soon. With this as a backdrop, Wielenga proceeded to write a desktop application on the fly using the NetBeans Platform (NetBeans 7.2).

Wielenga demonstrated building a new application from existing NetBeans constructs. He stated something that I wasn't aware of: there's not necessarily any requirement to use NetBeans IDE if using NetBeans Platform. He said the one connection is that you might think of the NetBeans IDE as the "reference implementation" of the NetBeans Platform.

There are "six quite small" JARs that are the minimum JARs needed for the modular-oriented NetBeans Platform.

Wielenga introduced the NetBeans Platform Showcase. He pointed out that one can get ideas for what can be done with the NetBeans Platform by looking at these examples and that many of them are even open source.

Wielenga talked about the NetBeans Platform supporting annotations so that Java developers can reduce their exposure to XML. The NetBeans Platform has an annotations processor that processes the in-code annotations and generates the appropriate XML.

One of the significant differences between NetBeans Platform and the Eclipse Rich Client Platform mentioned in this presentation is the NetBeans Platform's use of Swing (and JavaFX) versus Eclipse Rich Client Platform's use of SWT. An interesting observation made at JavaOne 2012 is the availability of eFX (NetBeans Platform meets JavaFX). JavaFX 2 allows for integration of JavaFX with Swing. This allows for an evolutionary path.

In a "slight diversion" (but one I thought was interesting), Wielenga mentioned that JDeveloper's best features can be more readily evolved into NetBeans. In this case, he used the specific example of JDeveloper's XML support. Earlier this week, the idea of using JDeveloper's UML support in NetBeans was mentioned.

An advantage of using the NetBeans Platform is that a decade's worth of lessons learned from practical experience building graphical user interfaces are incorporated into NetBeans Platform. Wielenga talked about the NetBeans Plugins Portal. An advantage of this is the ability to use pieces of software that have already been written and tested without needing to roll it out on one's own.

"The worst thing about Java Help" is the challenge of setting up the necessary XML content. NetBeans provides a wizard that handles this and makes it easy to generate an HTML representation of the help system.

Wielenga talked about one of the benefits of NetBeans Platform being that because it underlies NetBeans IDE, testing toolkits built for NetBeans IDE can often be applied to the applications based on the NetBeans Platform.

As a side note, NetBeans 7.3 is now available for download in beta form.

JavaOne 2012: Mastering Java Deployment

After grabbing an Italian Classic Combo for another JavaOne 2012 lunch, I headed to Hilton Imperial Ballroom B to see the presentation "Mastering Java Deployment." The speakers, both from Oracle, were Mark Howe and Igor Nekrestyanov.

Howe stated that a goal of the deployment team is to help Java developers deploy their applications to platforms of choice. He started by discussing "feature deprecation." In some cases, there are multiple ways to do the same thing. An example of this is jarjar and pack200. By deprecating redundant (especially older) approaches, they don't have to spend as much time supporting and fixing bugs on these seldom used things.

Howe showed a table of features being deprecated and removed in JDK 7, JDK 8, and JDK 9. In general, anything being deprecated and/or removed has alternatives and folks using the deprecated/removed features should start looking at which alternative works best for them.

As of JRE 7 Update 6, a totally Oracle-supported JRE will be issued for Mac OS X. Oracle's intention is to fix bugs and add features across JVMs for all deployment environments at the same time. The JRE 7 is "mostly compatible" with Apple's JRE 6. One change is to be more aligned with Oracle's JVM support for other platforms and have Oracle's updated update the JRE on Mac OS X rather than using the Mac "Software Update." One caveat is that "Chrome on Mac is currently unsupported (32-bit only)."

In continuing the theme of platform JVM feature polarity, JavaFX is now delivered with JRE for Linux. Howe's "Convergence of Java and JavaFX" slide showed a table indicating the progress of converging Java and JavaFX versions. The goal is for JavaFX to be one of the core libraries in the Java specification. Plans for JDK 8 include "Java launcher able to run JavaFX applications" and "jfxrt.jar on boot classpath for java and javac."

Howe introduced the Java Deployment Toolkit and described it as a "tool to simplify deployment of Java content in the browser." He contrasted deployJava.js ("original version") with dtjava.js ("better JavaFX support and portability"). The dtjava.js version "supports all deployment scenarios on all platforms" though there is no autostart on Mac or Linux.

Howe talked about WebStart and explained that "user experience is not quite as nice as you'd like it to be." He contrasted this with use of dtjava.js that allows developer to set parameters for control of launching from JavaScript. It makes for more control and better user experience. This also removes need for fixed code base. The code shown in a slide for using dtjava.launch requires JRE 7 Update 6 or later.

The goal of packaging tools is to "simplify deployment for application developers." The command-line tool bin/javfxpackager (or set of Ant tasks lib/ant-javafx.jar) can be used with JDK 7 Update 6. The "latest release of NetBeans" supports these.

Howe covered several motivations for completely self-contained applications. A self-contained applications contains "all the artifacts necessary to run your application." It has a private copy of the Java runtime and removes the dependency on the external JRE. Many of the motivations for self-contained applications revolved around issues of acquiring a current JRE to run the application.

Benefits of self-contained applications include the feeling of a native application, improved compatibility, easier deployment on a fresh system, optional administrative privileges, and support of newer distribution channels such as the Apple Apps Store. The caveats of self-contained applications include larger size (JRE included), "download and run" instead of WebStart's "click and launch," need to build package per platform, and other current limitations such as package needing to be built on the target platform and application updates being the responsibility of the developer."

To create a self-contained application, one needs JDK 7 Update 6 as well as optional third party tools such as WiX to build MSI on Windows. Howe showed a slide with Ant code for generating the self-contained application. The Developer Preview will allow a developer to select target version of JVM (current choices are JRE 7 Update 6 or JRE Update 10). The Developer Preview is expected to be available with JRE 7 Update 10. JDK 7 Update 10 is also anticipated to support Mac App Store support.

Like so many other presentations at JavaOne 2012, community feedback was solicited. In this case, the deployment team would like to know what people want and need for more effective web deployment of Java applications. Howe had a nice slide comparing executable JAR to WebStart to self-contained application.

Mac App Store does not allow applications to "rely on optionally-installed technology." Other requirements include need for application to "run in a sandbox" and "follow UI guidelines." Certain APIs (FileChooser) should be avoided. See JavaOne 2012 slides for "Deploy Your Application with OpenJDK 7 on Mac OS X" and future version of JavaFX Deployment Guide for more details.

Howe's "key points to remember" include merging of Java with JavaFX, new platforms for Java, new deployment options (self-contained application bundle and deployment to Mac App Store), and deprecation of old deployment features.

One of the attendees asked if there is a way to share a single JRE among multiple shared self-contained applications. The answer is that there currently is not a way to do this, but that a JRE can optionally not be included in the otherwise self-contained application.

In responses to another question, the speakers stated they are not aware of any plans to deprecate Swing. They also responded to yet another question that there is currently no Maven support for building self-contained applications (use Ant or NetBeans).

There were several good slides shown in this presentation that I'd like to look at more closely in the future. Fortunately, Howe stated that these will be made available. Much of what was covered in this session will be open source and audience members were encouraged to contribute to the open source projects.

JavaOne 2012: Up, Up, and Out: Scaling Software with Akka

After the late-ending Community Keynote, I headed to Hilton Golden Gate 3/4/5 to see Viktor Klang's (Typesafe) "Up, Up and Out: Akka" presentation. Klang is the technical lead on Akka. Akka is a "beautiful mountain in northern Sweden," is a Goddess, and is a Scala-based "toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on the JVM." Akka is not exclusive to Scala only and can be used "from Java today." Using Akka with Scala does allow you to do some things you cannot do with Akka when used with Java.

Akka is used by many large companies to solve real problems. Akka is built to scare in many directions and to provide extreme flexibility. One of Akka's goals is to "manage system overload."

Akka uses Actors: "Akka's unit of code organization." According to Klang, "Actors help you create concurrent, scalable, and fault-tolerant applications." Actors "keep many 'policy decisions' separate from the business logic." Actors originated in 1970s ("like all cool stuff in computer science") and Erlang has been using actors with "great success" for several years.

Klang warned to avoid "thinking in terms of shared state, a leaky abstraction." He added that threads and locks are "a means of execution" rather than structural. He said this mixes execution with business logic. Concurrent collections are good optimizations for local uses.

Actors are "distributable by design" and Klang had a slide listing several bullets explaining this statement. He stated that an actor can be an alternative to "a thread," "an object instance," "a callback or listener," "a singleton or service," "a router, load-balancer, or pool," "Java EE session bean or Message-Driven Bean," "out of process service," and "finite state machines."

Klang referenced a video of Carl Hewitt on actors. An actor is a "fundamental unit of computation that embodies several key characteristics."

Klang showed code examples in my preferred format in a presentation: embedded in his slides with color syntax highlighting. He showed step 0 ("DEFINE") in which his code defined the Actor's class and the Actor's behavior.

Once defined, the first operation (I - "CREATE") "creates a new instance of an Actor." The created Actor is extremely lightweight and its "state and behavior are indistinguishable from each other." He drove this last point home: "The only way to observe state is by sending an actor a message and seeing how the actor reacts." The Actor is "very strong encapsulation" of state, behavior, and message queue.

Akka provides an ActorSystem for creating Akka Actor instances. An instance of Props is provided to the Actor because actors need props.

Step 2 ("SEND") involves "sending a message to an Actor" and "everything happens reactively" and "everything is asynchronous and lockless." Akka supports a "fire and forget" mode with the actor's tell method. However, Akka provides guaranteed order of delivery. The reply is implemented in Akka with getSender().tell().

Step 3 ("BECOME") "redefines the Actor's behavior" and is "triggered reactively by receipt of message." The reasons one might want to change the behavior of an actor at runtime include supporting highly contended actor transforming to an actor pool or to implement graceful degradation.

Actors can supervise other Actors, leading to Step 4 ("SUPERVISE"). A "supevisor detects and responds to the failures of the Actor(s) it supervises" and Klang stated that this translates to "a clean separation and processing and error handling."

Klang talked about "failure management in Java, C, and C#" where you are "given a single thread of control." He put it this way in a bullet: "If this thread blows up, you are screwed." The implication of this is that all "explicit error handling" is done "within the single thread" and "tangled up" with the business code.

Klang said the way to deal with error handling is to push the error handling out away from the business logic. He then referenced the onion-layer error kernel. Klang talked about callbacks (preRestart and postRestart) provided for Actors to handle failures.

A Router is a special case of Actor. Klang showed a slide with code using a RoundRobinRouter. He also showed being able to define the deployment scenario outside of the code in configuration file and referencing that from the code with a path. He took this example even further to show code for "remote deployment" specifying a URL with the "akka" protocol, a host name, and a port.

Everything that Klang presented to this point is available today as Akka 2.0. Klang said that there will be Akka Cluster in the to-be-released-soon Akka 2.1. He asked for feedback to ensure that the correct APIs and correct functionality are available for clustering in Akka 2.2. More information on Akka clustering is available in the specification, the user guide, and the code itself.

Akka 2.1 will also feature Akka Camel based on Apache Camel. The Typesafe Console is also available to monitor an Akka application and there is a live demo of this available.

JavaOne 2012: Community Keynote

The third and final keynote, the Java Community Keynote, started the final day of JavaOne 2012. Although the first two keynotes were held in the Masonic Center, this one was held in Hilton Continental Ballroom.

Sharat Chander started the Community Keynote at the 17th JavaOne (JavaOne 2012). He stated that sixty percent of JavaOne 2012's content has been presented by the community. He said JavaOne is "by the community and for the community." He had those who participated on the submission committee stand up to receive recognition and applause. Chander's opening was perfect: it recognized the community, it was enthusiastic and was an appropriate duration.

Donald Smith joined Chander on the stage, acknowledged Chander's contributions to JavaOne, and started a wave in the audience in Hilton Continental Ballroom.

Gary Frost joined Donald Smith on stage to talk about Project Sumatra and Aparapi. It sounds like Project Sumatra is currently planned for JDK 9 (giving JDK 8 a change to introduce Lambda expressions).

An expert panel came to the stage to talk about their respective organizations' participation in the Java ecosystem. There were representatives from Eucalyptus, Twitter (Chris Aniszczyk, who stated that Twitter is built on JVM with Scala and Netty), Cloudera, Eclipse Foundation (Mike Milinkovich stated that the majority of Eclipse projects use Java), and Perrone Robotics (Paul Perrone).

One of the panelists stated that "low egos and high ambition level" coupled with desire to be truly innovative are what "smart venture capitalists" look for in startups. Another panelist stated, "Communities are great at innovation because they are open."

Georges Saab came to the stage to introduce one of the Duke's Choice Award winners. He had Martijn Verburg join him to talk about the London Java Community winning an award. Martijn talked about organizing a Java Users Group and the Adopt-A-JSR Program. Although I normally loathe the mixing of politics with technical seminars (my one and only complaint about the Colorado Software Summit), I have to admit that I laughed out loud when Verburg joked "if the presidential elections don't work out...the queen has agreed to take you back as a colony."

In another humorous quote, Bruno Souza explained Brazil's recent World Cup woes, "You cannot be good at everything, so Brazil will be good at Java." I also found another perspective of his interesting concerning spoken language (Portuguese/English) issues related to a programming language: "The important thing that user groups do is translate - to the local language, between technologies, and to bridge culture gaps" (as quoted by Trisha Gee). John K. Waters also captured another related Souza quote: "Java is the lingua franca" that transcends other language differences."

Paul Perrone of Perrone Robotics returned to the stage to discuss how Perrone Robotics uses Java with their Rumbles robotic vehicle. The bot used for the demonstration (Rumbles's "little brother") is built for outdoor use, so it had duct tape on its wheels so that it could have better traction inside (he said think chains on tires).

James Gosling was introduced with a bit of drama to talk about Liquid Robotics (Guillermo Castro called it!). Gosling explained that the robot he was talking about is not like the robots most of us think about with wheels or legs and arms. He talked about use of ARM processors, running Linux, and embedded C code.

One of the challenges Gosling discussed is to use as little power as possible, especially when in the "middle of a storm in the arctic" with no ability to use solar recharge. Due to high "Iridium satellite communication costs" ($1/kb or one million dollars for a terrabyte), they focus on using approach of short texts for communication. Gosling quipped, "We don't have a Big Data problem." Although they don't have a lot of data, what they do have is "precious." Gosling explained some of the hazards their robots face including big waves and even sharks.

Gosling built his own "NoSQL-ish" database and he said this was "either the most exciting thing or stupidest thing" he has done in a while. Gosling said he's been "a real Jelastic fan."

Although Gosling's presentation was interesting in its own right, I think the "effect" of having someone so obviously connected to Java and JavaOne return to speak at a JavaOne keynote (on the "other side" [community]) was probably more significant than the message itself.

As is typically the case with JavaOne keynotes, the Community Keynote went past its scheduled end time of 10:30 am. Gosling was allowed to take more than his allotted time, but this is not a big surprise for the "Father of Java." Gosling showed a demonstration using NASA World Wind (his "favorite Swing application," like "Google Maps with a real API"). Gosling stated to some applause, "It makes my head explode when there are people who think you can do everything in HTML." Gosling pointed out that he does like HTML and especially likes jQuery, but pointed out that some things are simply out of the realm of HTML still.

After throwing out some t-shirts, Chander asked for attendees to fill out the surveys to help make JavaOne more about the community. He also encouraged attendees to share knowledge with students and others wanting to learn Java. It has also been announced that Stephen Chin will be chair of next year's JavaOne.

Community has been a big theme of this edition of JavaOne and the Community Keynote is just one part of that. I have heard pleas for help and feedback from the community in a large percentage of the presentations and keynotes that I have attended this year.

JavaOne 2012: Diagnosing Your Application on the JVM

It was worth attending Staffan Larsen's (Oracle Java Serviceability Architect) presentation "Diagnosing Your Application on the JVM" (Hilton Plaza A/B) just for learning of the new jcmd command-line tool provided with Oracle's JVM 7. The rest of the presentation was "bonus" for me, which was nice for the last session I attended on Wednesday of JavaOne 2012.

The Oracle HotSpot JDK provides jcmd, a command-line tool designed to be both backwards compatible and forward adaptable for future versions of Java. It is designed to support new tools and features that come with new SDKs in a standardized approach. The following screen snapshot shows it used for most basic jps-like functionality (Larsen mentioned jps almost as briefly as I just did and referred to jcmd as "like jps but more powerful").

As the above image shows, jcmd can be used like jps.

Larsen showed some handy features of the jcmd command. He had some small sample Java applications that helped him to demonstrate jcmd. For my purposes, I'm running jconsole in one terminal on my machine and then I'll run jcmd commands against that JVM in which jconsole is running. The next screen snapshot shows how the basic (no arguments) jcmd call provides information on that JConsole process.

jcmd supports execution against JVM processes either by process ID (pid) or by process name. The next screen snapshot shows running jcmd against the JConsole process by that name and passing it help to see which options can be run against that particular process. Note that I tried unsuccessfully to run this against 'dustin' (no existing process) to prove that jcmd is really showing options available for running processes.

The feature demonstrated in the last screen snapshot is one of the most compelling reasons for moving from existing command-line tools provided with the Oracle JDK to jcmd. This image shows how jcmd can provide a list of the available options on a per process basis, allowing for ultimate flexibility in terms of supporting past versions or future versions of Java that support different/new commands.

Just as jcmd <pid> help (or replace pid with process name) lists the available operations that can be run by jcmd against a particular JVM process, this same help mechanism can be run against any one of those specific listed commands [with syntax jcmd <pid> <command_name> help (or use process name instead of pid)], though I could not get this to work properly on my Windows machine.

The next image shows actually running that command against that JVM process rather than simply asking for help on it.

In the two screen snapshots immediately above, I ran jcmd against the pid instead of the process name simply to show that it works against both process ID as well as name. The next screen snapshot shows executing jcmd against the JVM process to get VM flags and command-line options from the JVM process (the pid of this instance of JConsole process is 3556).

Running jcmd's Thread.print command against a supporting JVM process makes easy work of viewing the targeted JVM's threads. The following output is generated from running jcmd JConsole Thread.print against my running JConsole process.

3556:
2012-10-04 23:39:36
Full thread dump Java HotSpot(TM) Client VM (23.2-b09 mixed mode, sharing):

"TimerQueue" daemon prio=6 tid=0x024bf000 nid=0x1194 waiting on condition [0x069af000]
   java.lang.Thread.State: WAITING (parking)
 at sun.misc.Unsafe.park(Native Method)
 - parking to wait for  <0x23cf2db0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
 at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
 at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
 at java.util.concurrent.DelayQueue.take(DelayQueue.java:209)
 at javax.swing.TimerQueue.run(TimerQueue.java:171)
 at java.lang.Thread.run(Thread.java:722)

"DestroyJavaVM" prio=6 tid=0x024be400 nid=0x1460 waiting on condition [0x00000000]
   java.lang.Thread.State: RUNNABLE

"AWT-EventQueue-0" prio=6 tid=0x024bdc00 nid=0x169c waiting on condition [0x0525f000]
   java.lang.Thread.State: WAITING (parking)
 at sun.misc.Unsafe.park(Native Method)
 - parking to wait for  <0x291a90b0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
 at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
 at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
 at java.awt.EventQueue.getNextEvent(EventQueue.java:521)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:213)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

"Thread-2" prio=6 tid=0x024bd800 nid=0x4a8 in Object.wait() [0x04bef000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x2917ed80> (a java.io.PipedInputStream)
 at java.io.PipedInputStream.read(PipedInputStream.java:327)
 - locked <0x2917ed80> (a java.io.PipedInputStream)
 at java.io.PipedInputStream.read(PipedInputStream.java:378)
 - locked <0x2917ed80> (a java.io.PipedInputStream)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
 - locked <0x29184e28> (a java.io.InputStreamReader)
 at java.io.InputStreamReader.read(InputStreamReader.java:184)
 at java.io.BufferedReader.fill(BufferedReader.java:154)
 at java.io.BufferedReader.readLine(BufferedReader.java:317)
 - locked <0x29184e28> (a java.io.InputStreamReader)
 at java.io.BufferedReader.readLine(BufferedReader.java:382)
 at sun.tools.jconsole.OutputViewer$PipeListener.run(OutputViewer.java:109)

"Thread-1" prio=6 tid=0x024bd000 nid=0x17dc in Object.wait() [0x047af000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x29184ee8> (a java.io.PipedInputStream)
 at java.io.PipedInputStream.read(PipedInputStream.java:327)
 - locked <0x29184ee8> (a java.io.PipedInputStream)
 at java.io.PipedInputStream.read(PipedInputStream.java:378)
 - locked <0x29184ee8> (a java.io.PipedInputStream)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
 - locked <0x2918af80> (a java.io.InputStreamReader)
 at java.io.InputStreamReader.read(InputStreamReader.java:184)
 at java.io.BufferedReader.fill(BufferedReader.java:154)
 at java.io.BufferedReader.readLine(BufferedReader.java:317)
 - locked <0x2918af80> (a java.io.InputStreamReader)
 at java.io.BufferedReader.readLine(BufferedReader.java:382)
 at sun.tools.jconsole.OutputViewer$PipeListener.run(OutputViewer.java:109)

"AWT-Windows" daemon prio=6 tid=0x024bc800 nid=0x16e4 runnable [0x0491f000]
   java.lang.Thread.State: RUNNABLE
 at sun.awt.windows.WToolkit.eventLoop(Native Method)
 at sun.awt.windows.WToolkit.run(WToolkit.java:299)
 at java.lang.Thread.run(Thread.java:722)

"AWT-Shutdown" prio=6 tid=0x024bc400 nid=0x157c in Object.wait() [0x04c6f000]
   java.lang.Thread.State: WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x2918b098> (a java.lang.Object)
 at java.lang.Object.wait(Object.java:503)
 at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:287)
 - locked <0x2918b098> (a java.lang.Object)
 at java.lang.Thread.run(Thread.java:722)

"Java2D Disposer" daemon prio=10 tid=0x024bbc00 nid=0x3b8 in Object.wait() [0x0482f000]
   java.lang.Thread.State: WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x2918b128> (a java.lang.ref.ReferenceQueue$Lock)
 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
 - locked <0x2918b128> (a java.lang.ref.ReferenceQueue$Lock)
 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
 at sun.java2d.Disposer.run(Disposer.java:145)
 at java.lang.Thread.run(Thread.java:722)

"Service Thread" daemon prio=6 tid=0x024bb800 nid=0x1260 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread0" daemon prio=10 tid=0x024c6400 nid=0x120c waiting on condition [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x024bb000 nid=0x1278 waiting on condition [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x024bac00 nid=0xe3c runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x024a9c00 nid=0x15c4 in Object.wait() [0x046df000]
   java.lang.Thread.State: WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x2918b358> (a java.lang.ref.ReferenceQueue$Lock)
 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
 - locked <0x2918b358> (a java.lang.ref.ReferenceQueue$Lock)
 at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
 at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)

"Reference Handler" daemon prio=10 tid=0x024a4c00 nid=0xe40 in Object.wait() [0x0475f000]
   java.lang.Thread.State: WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x2917e9c0> (a java.lang.ref.Reference$Lock)
 at java.lang.Object.wait(Object.java:503)
 at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
 - locked <0x2917e9c0> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x024a3800 nid=0x164c runnable 

"VM Periodic Task Thread" prio=10 tid=0x024e7c00 nid=0xcf0 waiting on condition 

JNI global references: 563

Larsen showed how to use thread information provided by jcmd to resolve a deadlock.

Larsen showed getting a class histogram from the running JVM process with jcmd. This is done using the command jcmd <pid> GC.class_histogram. A very small subset of its output is shown next (the pid of this JConsole process is 4080 this time).

4080:

 num     #instances         #bytes  class name
----------------------------------------------
   1:          1730        3022728  [I
   2:          5579         638168  
   3:          5579         447072  
   4:           645         340288  
   5:          4030         337448  [C
   6:           645         317472  
   7:           602         218704  
   8:           942         167280  [B
   9:           826          97720  java.lang.Class
  10:          3662          87888  java.lang.String
  11:          2486          79552  javax.swing.text.html.parser.ContentModel
  12:          3220          77280  java.util.Hashtable$Entry
  13:          1180          67168  [S
  14:          2503          60072  java.util.HashMap$Entry
  15:           181          59368  
  16:           971          43584  [Ljava.lang.Object;
  17:          1053          41160  [[I
  18:           206          29040  [Ljava.util.HashMap$Entry;
  19:           111          27880  [Ljava.util.Hashtable$Entry;
  20:           781          18744  java.util.concurrent.ConcurrentHashMap$HashEntry
  21:          1069          17104  java.lang.Integer
  22:           213           9816  [Ljava.util.concurrent.ConcurrentHashMap$HashEntry;
  23:           202           9696  java.util.HashMap
  24:           201           9280  [Ljava.lang.String;
  25:            24           8416  [[I

Larsen also demonstrated jstat and several of its useful functions. He demonstrated use of jstat -gcnew (new generation behavior), jstat -precompilation (compilation method statistics), and jstat -options (displays options).

During the course of his presentation, Larsen needed to convert a decimal number (pid?) to its hexadecimal representation for comparing it to the output of another tool. He used the handy printf "%x\n" <pid> command to get the hexadecimal representation of the pid.

Larsen demonstrated use of VisualVM to compare two heap dumps and browse a heap dump. He also demonstrated the VisualVM Profiler.

Larsen moved from the tools previously covered aimed at running JVMs to tools that can be used to analyze JVM core files. He returned to jstack to analyze contents of the core file.

Larsen talked about remotely accessing JVM information via JMX and tools like jconsole and jvisualvm. He demonstrated that jcmd can be used to start JMX exposure as well: ManagementServer.start "with a bunch of parameters." Larsen feels that VisualVM and JConsole would use ManagementServer.start rather than Attach API if implemented today.

jstat can also connect to daemon remotely through use of jstatd. There is no encryption or authentication with jstatd.

jps and jcmd find what's running on system using "well-known file for each JVM": /hsperfdata_<user>/<pod> This file is created on JVM startup and deleted on JVM shutdown. Unused previous files are deleted on startup, so jps and jcmd, as Java programs themselves, will clean these old ones up.

The Attach API "allows sending 'commands' for executionin the JVM," but only works on local machine and for current/same user. This is what jcmd and jstack use. Larsen then went onto explain the different mechanics of using the Attach API for Linux/BSD/Solaris (uses temporary file creation) versus Windows (uses code injection). I employed the Attach API in my post Groovy, JMX, and the Attach API.

Diagnostic commands are "helper routines inside the JVM" that produce "text output." They can be executed via the jcmd utility (and soon via JMX). They each have a self-describing facility: jcmd PerfCounter.print to see the raw contents.

Larsen showed an informative table comparing "communicating with the JVM" approaches: attach, jvmstat, JMX, jstatd, and Serviceability Agent (SA). The SA "should be used as a last resort ('typically for a JVM that is hung')" and uses a "debugger to read information."

Larsen transitioned to talk of future tools. He started this portion of the presentation with coverage of Java Flight Recorder. Java Flight Recorder is a "JVM-built-in profiler and tracer" with "low overhead" and is "always on." Other coming tools are Java Mission Control ("graphical tool providing very detailed runtime monitoring details"), more diagnostic commands for jcmd ("eventually replacing jstack, jmap, jinfo" for various reasons), JMX 2.0 ("something we're picking up again; it was started a very long time ago"), improved logging for JVM (JVM Enhancement Proposal [JEP] 158), and Java Discovery Protocol (anticipating forthcoming JEP for this).

One question asked was if one could see MBeans in VisualVM as can be done in JConsole. As I've blogged on, there is a VisualVM plug-in for doing just that.

Although I felt somewhat comfortable with the Oracle HotSpot JDK command line tools, I was unfamiliar with jcmd and appreciated Larsen's coverage of it. I learned some other things along the way as well. My only complaint is that Larsen's presentation (especially the demonstration) was so rapid fire and so content-rich that I wish I could see it again.

A related (but older) presentation with some of the same content is available at http://www.oracle.com/javaone/lad-en/session-presentations/corejava/22260-enok-1439100.pdf

Wednesday, October 3, 2012

JavaOne 2012: What's New in Groovy 2.0

Guillaume Laforge's (SpringSource/VMware/@glaforge) "What's New in Groovy 2.0" presentation was in the same conference room (Hilton Golden Gate 6/7/8) as Martin Odersky's "What's New in Scala 2.10" presentation, but I decided to leave the room between these sessions for three reasons:

  1. You tend to get kicked out of a room before the next session anyway to ensure that registered individuals get equal opportunity to "the good seats" (and probably to make sure someone not registered for the session doesn't displace someone who is registered for the most popular sessions)
  2. This is the longer-than-normal one-hour break (no such break tomorrow on the final day of JavaOne 2012)
  3. The outside temperature is significantly lower than yesterday and it's refreshing to stand in a shaded area outside while a cool breeze blows between the buildings

Laforge introduced himself and the way he says his own name with intentional French accent is far cooler than how I pronounce his name. He is the Groovy Project Manager at VMWare, the initiator of the Grails framework, creator of Gaelyk, and a co-author of Groovy in Action. Laforge is another speak who likes to take questions as they come.

Laforge listed some features introduced with Groovy 1.8 command chains, gpars (concurrency/parallelism), closures improvements, built-in JSON support, and new AST Transformations.

Laforge showed a command chain that looked like English words but is really an alternative combination of methods and parameters (every other word is a method name with the words in between being the parameters to the preceding method name). With some exceptions, command chains allow code to be written without parentheses and some other types of punctuation. He showed several examples of this, including use of commas for multiple arguments. He also explained that no-argument methods do require parentheses.

GPars is "bundled in the Groovy distribution" with Groovy 1.8 and "covers a wide range of parallel and concurrent paradigms." He emphasized that this can be used "from plain Java as well!" GPars is friendlier for Groovy developers.

Closure annotation parameters is the ability to use closures within annotations. This is achieved by encoding the closure in the form of a class.

Because "closures are used a lot in the context of functional programming" and because Groovy has a "functional flavor especially with the use of closures," Groovy closures in Groovy 1.8 support closure memoization. This feature potentially brings performance improvements due to caching of results for same parameters to the same closure. More granularity in terms of the number of times to use cache for closure results is available via methods like memoizeAtLeast, memoizeAtMost, and memoizeBetween.

Laforge explained that Groovy introduced from the beginning powerful XML marashaling and unmarshaling capabilities "back when XML was popular." He said it was thus quite natural to add built-in JSON support similar to that XML support. He then showed code samples (embedded within the slides like I prefer) indicating how to use JsonSlurper to consume JSON content and how to use JsonBuilder to generate JSON content.

Groovy 1.8 introduced some new Groovy ASTs as discussed in the earlier JavaOne presentation A Walk Through of Groovy's AST Transformations. He had some nice slides that combined simple text bullets of select AST Transformations with a simple code snippet using that AST Transformation. The new Groovy 1.8 AST Transformations that he covered included @Log, code execution controlling (@ThreadInterrupt for example), @ToString, @EqualsAndHashCode (similar transforms to Project Lombock), @TupleConstructor, @InheritConstructors (replicate all parent class's constructors such as when writing a class that overrides Exception).

At exactly the half-way point in his presentaion, LaForge transitioned to coverage of Groovy 2.0. He stated that it was released in June 2012 and some "other dot releases" have been released since then with "bug fixes and so on." The key themes of Groovy 2.0 include modularity, JDK 7 alignment,

Groovy's single "all" JAR "weighs in at 6 MB," but "nobody needs everything." The new core JAR in Groovy 2.0 is half that sizs (3 MB) and there are module-specific JARs. The "big Groovy old JAR" is still available if you'd like to use it.

The effort to make Groovy modular led to the "extension modules" concept. This allows a developer to "contribute instance extension methods." This feature works with static type checking and is IDE friendly, two advantages that some of the other Groovy approaches for adding dynamic methods do not equally enjoy. These are structured similarly to Groovy Categories and require a descriptor in META-INF/services/org.codehaus.groovy.runtime.ExtensionModule.

Because "Groovy supports 99% Java syntax," Groovy supports JDK 7 enhancements such as underscores in numeric literals, multicatch exception handling, and better runtime performance due to use of invokedynamic.

One of the biggest new features in Groovy 2.0 is static type checking, which Laforge's first bullet put this way, "Goal: make Groovy compiler grumpy!" Laforge went on to show Groovy code samples with things in the code that will lead to compile-type breakage. He showed off the @TypeChecked annotation. There are aspects of Groovy that cannot be type checked by a compiler. An example of this is the builders prevalent in Groovy. This is what makes using @TypeChecked useful: use it where type checking makes sense and not where it doesn't make sense.

Laforge went on to show how Groovy allows avoidance of explicit casting after an instanceof check as a specific example of Groovy's type inference. Another Laforge example demonstrated how Groovy's static type checking catches changing of data type in the same code.

Laforge listed several "gotchas" with static type checking. For example, static type checker cannot allow use of dynamic metaClass. Another gotcha example is that the implicit "it" variable in a closure body cannot be assured to be a certain type. There is a Groovy Enhancement Proposal to make it so that this situation can be type checked. It seems that anytime Groovy cannot guarantee the type during static type checking, that situation is not allowed. This does seem to be the safest approach.

Advantages of static Groovy code include type safety, faster code, and immunity from monkey patching. The price for this is loss of dynamic features and dynamic dispatch. One audience member asked why one wouldn't always use static compilation and the answer is that many of us like being able to use the builders and other Groovy dynamic features. You can use the @CompileStatically annotation for portions to be compiled statically.

Groovy 1.8 primitive optimizations have dramatically improved performance and Groovy 2.0 static compilation closes gap with Java in Fibbonacci, Pi Quadrature, Binary Trees micro benchmarks. (Laforge did issue the usual caveats about performance benchmarks.)

Groovy 2.0 introduces modularity, Project Coin, invokedynamic, static type checking, and static compilation.

One interesting side note that Laforge mentioned is that "it is possible that Groovy 3 will require JDK 7" (to use invokedynamic). Laforge's slides are already posted online.