At the Google Developer Day conference 2008 in Sydney, Lars Rasmussen, the head of engineering for Google Australia gave an overview of the Google Web Toolkit (GWT) with his presentation “AJAX with Google Web Toolkit”.

What is GWT?

GWT is an open source, cross-browser framework that allows developers to write AJAX applications in Java and get the bytecode compiled into JavaScript. Rasmussen says Google didn’t choose Java because of a particular attachment to the language, but because of the abundance of tools out there available for Java. According to Rasmussen the final code you end up with will be faster and smaller than what you would write yourself.

GWT enables software development capabilities with AJAX. These are some of its advantages:

|> Java IDEs — you can use any Java IDE or Notepad if you prefer
|> Quick editing, testing, debugging and refactor cycle — the browser lets you debug code at Java level. You start your hosted browser in debug mode, edit your Java code, refresh your browser and you will see the changes straight away
|> Unit testing — GWTTestCase class is provided so that it can be integrated with JUnit
|> Reuse through jars — Modules or jar files of one application can be referenced from another
|> Make the most of Object Oriented design principles
|> Javadoc — GWT API documentation
|> Compile time errors — With Eclipse the errors are fixed as you are typing code

GWT preserves the principles of Web usability by: providing regular UI elements; enabling keyboard-only use and font size preferences; allowing the user to be in control of the browser; facilitating a fast start-up; and, allowing the user to feel like they are using a standard Web app, but with an enhanced experience.

History

GWT’s history API provides a means for you to access the browser’s history stack and control what happens when the back or reload button is clicked.
This way, even if you click the back button you can still return to the same state of the app.

Some aspects of the API are: the historyToken parameter is the current history state so each item in the history stack is called a token; HistoryListener is triggered when the back or forward button is clicked, you would implement this to get notified when there is a change to the browser history; you can create new history items on the stack — for instance, History.newItem(token); hyperlink class provides a link to a different state of the app where it creates a new history item without reloading the page.

Internationalisation

GWT provides a way for you to internationalise your applications and libraries. With the I18N package you can translate your apps into other languages.

To create localised messages, you need to implement the Messages interface and then add the corresponding localised properties files. .properties files store the translated strings.

Controlling the look of widgets with CSS

With GWT you can control the look of your widgets using CSS and keep the code and presentation separate. Every widget has a style name which is associated with a CSS rule.

To change the font size of all your buttons, as demonstrated here, you would do the following:

.gwt-Button { font-size: 150%; }

Optimised Permutations

GWT compiler constructs multiple compilations based on all possible permutations and records them in a file — suffix.cache.html

The end-user only downloads one optimised compilation for their particular circumstances. For instance, a compilation for Firefox 3 and UK English. The performance is optimised, because the user is downloading only what is relevant to them.

JavaScript Native Interface (JSNI)

JSNI allows you to incorporate JavaScript into your Java code with the use of the native keyword. The JavaScript code in JSNI methods is encapsulated inside a comment block. It starts with /*-{ and ends with }-*/ and is inserted between the parameter list and the ending semicolon.

What’s new in GWT 1.5?

Some of the features in the release candidate for 1.5 are:

|> Java 5 support (enums, annotations, autoboxing etc)
|> An improved compiler to make apps faster
|> Additions to the UI library such as widget animations
|> DOM API — to make DOM development easier
|> Improvements to internationalisation
|> Accessibility Support
|> Improvements to JRE Emulation Library

If you want to play around with it, you can download it here.