JavaOne 2012 – Day 3

For me, finding time to blog in between sessions is almost impossible in JavaOne. Going back and forth between different hotels and trying to be in the room early enough to secure a nice seat are time consuming. And when you factor in the fact that the BOF (Birds of a Feather) sessions may end as late as 21:15, I’m not left with many viable options for blogging. Normally I’m a night owl. I can work well and be pretty productive late at night. However, this year I’m trying something new. I’m waking up at 5 AM to get some work done early in the morning.

When I blog about a day’s sessions, ideally I try to select a few sessions, the most interesting ones. But sometimes there are so many good sessions that it becomes really difficult to short-list them. Wednesday (javaOneDays[3]) was such a day when three of my Top 5 sessions took place. As an attendee it is a wonderful thing. However as a blogger it makes life harder.

JavaOne Schedule Builder Kiosk

JavaOne Schedule Builder Kiosk that I mentioned in a previous blog entry.

Servlet API 3.1The first session of the day was about Servlet API 3.1 and it was entitled What’s New In Servlet 3.1: An Overview. Servlet API is most of the time too low level to be directly used in Enterprise software development but it is important to at least be familiar with it not only because sometimes it becomes necessary to use it also because it is the underlying technology of many other Java APIs and frameworks.

During their talk, the speakers classified the new and noteworthy under 3 main headings:

  • Scalability (e.g. exposing non-blocking IO API)
  • Support for newer technologies that use HTTP (e.g. WebSocket)
  • Security enhancements

Non-Blocking IO API

If you’ve worked with the Servlet API before then you know that reading from the ServletInputStream and writing to the ServletOutputStream are blocking operations. The addition of non-blocking IO to the Servlet API introduces new APIs to ServletInputStream and ServletOutputStream, and two new event listeners: ReadListener and WriteListener. 

We can now set a ReadListener by using ServletInputStream‘s new setReadListener() method. There’s also a new setWriteListener() method in ServletOutputStream. Because those listeners are used for non-blocking IO, there are also new verification methods such as SetvletInputStream.isFinished(), ServletInputStream.isReady() and ServletOutputStream.canWrite(). As one of the attendees highlighted it, it is surprising to see that the draft specification includes a conflicting naming convention: isReady() and canWrite(). Why not canRead() and canWrite()? Or even isReady() for both interfaces?

Here’s how those new event listener interfaces look like:

public interface ReadListener extends EventListener {
  public void onDataAvailable(ServletRequest request);
  public void onAllDataRead(ServletRequest request);
  public void onError(Throwable t);

public interface WriteListener extends EventListener {
  public void onWritePossible(ServletResponse response);
  public void onError(Throwable t);

For example, rather than using the blocking read() method of ServletInputStream we can use the setReadListener() method and execute the reading operation within our ReadListener implementation.

From the examples given during the talk I much preferred the one that combined non-blocking IO and async processing. The simple doGet() method looked like this:

ServletInputStream sis = request.getInputStream();
ServletOutputStream sos = request.getOutputStream();
AsyncContext ctx = req.startAsync();

sis.setReadListener(new SimpleReadListener(sis, sos, ctx));

int b = -1;
while (sis.isReady() && ((b = != -1)) {

if (sis.isFinished()) {

And the SimpleReadListener looked like this:

public class SimpleReadListener implements ReadListener {
  public void onDataAvailable(ServletResponse resp) {

  public void on AllDataRead() {

  public void onError(final Throwable t) {

Protocol Upgrade

Protocol upgrade is part of HTTP protocol. It allows an already established connection to switch to a new and incompatible protocol. When the client initiates a request (GET, POST, etc) it can insert an Upgrade header to it indicating the desired protocols in order of preference. Upon receipt of request, the server can accept or refuse the new protocol.  If the server accepts the protocol upgrade then it sends back a 101 Switching Protocol along with an Upgrade header containing the chosen protocol.

Using Protocol Upgrade the client and the server can switch from HTTP 1.1 to another protocol such as HTTP 2.0, SHTTP 1.3, IRC 6.9 or Web Socket. For example:


GET /chat HTTP 1.1
Upgrade: websocket
Connection: Upgrade


HTTP 1.1 101 Switching Protocol
Upgrade: websocket
Connection: Upgrade

Servlet 3.1 adds 2 new interfaces to the javax.servlet.http package: ProtocolHandler and WebConnection. It also adds a new method to HttpServletRequestupgrade(ProtocolHandler handler).

As part of their talk the presenters created an EchoProtocolHandler that implemented the new ProtocolHandler interface. An instance of EchoProtocolHandler was then used as the parameter to the new upgrade() method call to demonstrate upgrading to a simple echo protocol.

Security Enhancements

The new specification brings clarifications on various areas such as:

  • run-as in the case of #init and #destroy.
  • default security semantic for non-specific HTTP methods
  • in a case where the same parameter name is used in the query string and as part of the POSTed parameters (what is its value?)

It also provides protection against some known security problems such as the Session Fixation Attacks.

tiggzi logoMax Katz‘s Building HTML5 Mobile Apps with Cloud Services made my Top 3 sessions list in this year’s JavaOne. He was a great and engaging speaker who mastered his subject and used his presentation material adroitly. He talked about Tiggzi and I was really impressed by this tool. You can probably guess the nature of this session by the fact that Max only had a single slide for the whole hour. Executed well, this type of slideless, live-demo-centric presentations can be the best type of technical sessions. Throughout his talk, Max incrementally developed a live application. As of this writing, the last version is still live on Unfortunately the app was modified towards the end of the session to demonstrate tiggzi’s capability of working with any existing RESTful services, which now points to the Devoxx‘s schedule.

Tiggzi is a cloud-based mobile application IDE. An application built by Tiggzi uses the following technologies:

  • jQuery Mobile
  • HTML5, CSS
  • JavaScript
  • PhoneGap

Tiggzi is a Web-based tool and it has a very slick UI. The components of the developed application are put together using drag & drop. The first application that Max built (I keep thinking about writing “we built”. I guess I felt it so because the presentation was very engaging and also because we, the audience, became testers using our mobile phones to validate the newly built application) was a twitter search app. Max quickly put together a few components to prepare the app visually. On the left hand side of the tool, there was a component gallery to choose from. Creating the UI looked as simple as dragging the desired components and dropping them on the phone view that sits in the middle, on the main panel.  And the selected component had its properties and its possible event bindings on the right hand side of the screen. Testing looked very simple: it was a matter of hitting the “Test” button.

Tiggzi knew how to consume JSON and XML services. Using twitter’s existing REST services, Max provided the necessary data to the application. He entered the service URL, added service request parameters and tested the service endpoint as a verification. The service endpoint was set up correctly so he defined the response structure. Mapping the service to UI components was done using drag & drop as well. I liked the way that it was represented with the request or response structure on the left, the UI component tree on the right and various arrows from left to right connecting them.

After that the app was just working. Max built an APK and at the same time the app was published as a Web app so that we, the attendees, could access the app using our own phones. Even though the requirements were very simple (twitter search), using tiggzi, it was extremely quick to achieve the desired happy path. Tiggzi also had a database console where Max could create an application database. The remaining of the session Max improved the application incremental additions.

I had some of our RESTful services in mind when the realization struck me. And I got the confirmation from Max: Tiggzi works with public services. It can’t create an app that integrates with your company’s private services. The service endpoints need to be public. But I’m signing up for a free trial nonetheless. I’d like to try tiggzi for myself.

Kotlin LogoThe following session was another one that made my Top 3 list: Incompetence * Motivation = Innovation? (How Kotlin and Other New Things Emerge) presented by Andrey Breslav, Lead Language Designer in JetBrains.

Andrey started his talk by explaining why listening to incompetent people was important. They have requests to make their lives easier however, most of the time, they don’t know what they are talking about. Even though you say “it doesn’t work that way” or “it’s not possible”, their message is clear: “change the world” because they can think out-of-the-box without knowing it. Incompetence is great for requirements. Competence is great for implementation.

After briefly explaining the reasons why a new language makes sense, Andrey cited some of the common language complaints that he keeps hearing and explained how Kotlin addresses those issues :

  • We hate writing stupid constructors!
  • And getters/setters!
  • We want to use fields!
  • Can’t I just say 3.toString()?
  • String doesn’t have enough methods!
  • One return value is too restricting!
  • List<String> contains objects, doesn’t it?
  • Can you figure out those nulls?
  • Doesn’t know that <TD> must be inside a <TR>?
  • I could use it for the browser, types and all.

Kotlin is a statically-typed JVM-targeted programming language. I like its “for industrial use” label. Code written in Kotlin compiles at least as fast as its Java counterparts. And one of the things I really like about Kotlin is its approach to nullable types and NullPointerException. Its type system is designed to prevent unwanted NullPointerExceptions. Kotlin (or rather its type system) distinguishes between nullable and non-nullable references. (Andrey mentioned that they had a tool (also still in development) that was capable of scanning the standard Java libraries to find nullable objects).

For example, the following name variable is not nullable and the second line causes a compilation error:

var name : String = "yagiz"
name = null // compilation error

The following declaration allows nulls:

var name : String? = "yagiz"
name = null // no error

The question mark that follows the type does the trick and indicates that this is a nullable type.

Kotlin has also a safe call operator (?.):


The call above returns name‘s length if name is not null or it returns null otherwise.

And if you still want a NullPointerException thrown when name is null then you can use the !! operator:

val length = name!!.length()

Compare to Scala this produces a better approach because it’s less verbose and Scala’s Option type comes with runtime overhead as its values are wrapped into Option objects.

Kotlin has other pretty cool features such as ClosuresExtension Functions (two of the rare things that I like about Objective-C are the similar Categories and Class Extensions), Variable Type Inference

If you are like me, you’re probably asking yourself how Kotlin compares to other languages, especially to Scala. They have some differences and official Kotlin documentation has a comparison list but the important thing to remember is: If you are happy with Scala, you probably don’t need Kotlin. However if you are looking for an improved way of writing JVM applications then Kotlin looks like a good contender to top the list.

Apache FoundationThe last session that I wanted to talk about in today’s blog was Heath Kesler‘s Advanced Enterprise Architectures Using Open Source however I realize that this has been a pretty long blog post therefore I’m going to leave it for the next article, which is going to be cover last day of JavaOne 2012.

, , , , , , , , , ,

  1. #1 by Andrey Breslav on October 8, 2012 - 3:09 pm

    Thanks for the kind words about Kotlin and my talk. The slides are available here:

    • #2 by Yagiz Erkan on October 8, 2012 - 4:03 pm

      Hi Andrey. Thanks for dropping by and sharing the link to the slides. And thanks again for such a great talk.

  2. #3 by Max Katz (@maxkatz) on October 8, 2012 - 8:59 pm

    Thanks for mentioning and glad you enjoyed the session. I updated the app with links to all three parts that I built during the talk.

    Frame version:

    No frame:

    • #4 by Yagiz Erkan on October 8, 2012 - 9:30 pm

      Hi Max. Thanks very much.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: