Home > Software Development > Learning Google Web Toolkit

Learning Google Web Toolkit

March 28th, 2011 Leave a comment Go to comments

Google Web Toolkit is an interesting project. It’s basically an AJAX toolkit but presents itself as a Java toolkit. The idea is that you still write Java code as you would with Java AWT, SWING, and the GWT converts it to JavaScript code for you.

But why don’t write JavaScript code directly? Well, you may know Java better than JavaScript. More importantly, Java is a typed language and easier to develop a large system than JavaScript.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


Using GWT for Java developers is mostlya piece of cake. You need to download and install JDK, GWT SDK, Eclipse, Google plug-in, and the recently Instantiation designer. The designer is from acquisition of Instantiation and really optional, but it’s a great tool that can make your life easier especially for prototyping. The nice thing about the designer is that the code generated is pretty human readable, thus easy to modify.

Of course, GWT code is different from a typical Java code. One noticeable difference is the GWT code has entry point instead of the main() in a typical Java application. You also need to know how to embed the Java code (to be compiled to JavaScript) into host HTML page and how to change component styles using CSS. The GWT also support XML based GUI development called UIBinder, similar to the XAML in WPF.

If you are using Eclipse with Google plugin, debugging GWT web application is very similar to other applications.

An advanced feature in GWT is the RPC (Remote Procedure Call) that facilitates the client (JavaScript) and Server (Servlet) communication. You don’t need to worry about the details like serialization and de-serialization, but to define an interface X that extends the “com.google.gwt.user.client.rpc.RemoteService”.

On the server side, you write implementation class Y that implements X and extends from “com.google.gwt.user.server.rpc.RemoteServiceServlet”. It’s pretty straight-forward.

On the client side, it’s a bit different. You need to create a corresponding asynchronous communication interface AsyncX with a bit of twisting on the interface. If you have a method as: (from Lars’ tutorial, the same for the next)

List<MyUser> getUserList();

The asynchronous version looks like:

void getUserList(AsyncCallback<List<MyUser>> callback);

Then you implement the AsyncCallback<List<MyUser>> interface in a class and register it with service so that the callback can be invoked when response comes back. It is not that straight forward. You’d better off to run through a sample for a better sense how it works.

While learning the GWT, I found the tutorial by Lars Vogel very helpful. It walks you through a right sized sample step-by-step within 2 hours. You can find many different tutorials from his web site. I highly recommend Lars’ tutorials.

  1. No comments yet.
  1. No trackbacks yet.