Google Web Toolkit

When a product is shipped from Google, a company most web application developers want to work for, it surely raises the interest levels of developers. Let me borrow some of the words from the Google web site. 
Google Web Toolkit (GWT) is a Java software development framework that makes writing AJAX applications who does not understand JavaScript. Writing dynamic web applications today is a tedious and error-prone process; you spend 90% of your time working around subtle incompatibilities between web browsers and platforms, and JavaScript's lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile.
GWT lets you avoid many of these headaches while offering your users the same dynamic, standards-compliant experience. You write your front end in the Java programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.

Here are some of the features that is important enough for you to note.

Since coding happens in Java you can make best use of the goodies that come in the Java world. At development time you can take support of an IDE like Eclipse, where debugging and error corrections are very easy.
To communicate from your web application to your web server, you just need to define serializable Java classes for your request and response. In production, GWT automatically serializes the request and deserializes the response from the server. GWT's RPC mechanism can even handle polymorphic class hierarchies, and you can throw exceptions across the wire. 
Your GWT applications automatically support IE, Firefox, Mozilla, Safari, and Opera with no browser detection or special-casing within your code in most cases.

Google Web Toolkit Architecture

GWT has four major components: a Java-to-JavaScript compiler, a "hosted" web browser, and two Java class libraries:



source: Google

The components, from bottom to top, are:


· GWT Java-to-JavaScript Compiler
The GWT Java-to-JavaScript compiler translates the Java programming language to the JavaScript programming language. You use the GWT compiler to run your GWT applications in web mode.

· GWT Hosted Web Browser
The GWT Hosted Web Browser lets you run and execute your GWT applications in hosted mode, where your code runs as Java in the Java Virtual Machine without compiling to JavaScript. To accomplish this, the GWT browser embeds a special browser control (an Internet Explorer control on Windows or a Gecko/Mozilla control on Linux) with hooks into the JVM.

· JRE emulation library
GWT contains JavaScript implementations of the most widely used classes in the Java standard class library, including most of the java.lang package classes and a subset of the java.util package classes. The rest of the Java standard library isn't supported natively within GWT. For example, packages like java.io don't apply to web applications since they access the network and local file system.

· GWT Web UI class library
The GWT web UI class library is a set of custom interfaces and classes that let your create web browser "widgets," like buttons, text boxes, images, and text. This is the core user interface library used to create GWT applications. GWT ships with the complete source code for the library under an open source license.

Sample code

Here is an example of a Tree as shown in figure 2. As you can see this is plain Java.

public class TreeExample implements EntryPoint {

public void onModuleLoad() {
// Create a tree with a few items in it.
TreeItem root = new TreeItem("root");
root.addItem("item0");
root.addItem("item1");
root.addItem("item2");

Tree t = new Tree();
t.addItem(root);

// Add it to the root panel.
RootPanel.get().add(t);
}
}

Pros

If you are Java web developer, then there are few reasons why you should ignore the GWT. It is by far the most stable Java web toolkit that generate JavaScript browser compatible code. It has number of interesting features that let you use it very efficiently. Using RPC with an Ajax application eliminates the necessity to explicitly deal with XMLHttpRequest and associated server return values, because the GWT objects handle the plumbing for you. Finally the documentation is excellent and there are quite a few examples that you can look at on the net.

Cons

It requires common sense to state that you need to know Java. And it is complicated to integrate with other JavaScript apps. We spent some time trying doing that, but errors were too many to handle.




Added on August 30, 2008 Comment

Comments

Post a comment