Tuesday, August 7, 2007

Why should I use Google Web Toolkit (GWT) ?

Google Web Toolkit (GWT) was launched by Google in May 2006 and the toolkit is being evaluated by web developers around the world. GWT enables AJAX based web applications to be coded in Java language. GWT will then convert Java code written for client side (browser) to JavaScript which can run on any Javascript enabled browser (most modern browsers are).

Pros:

  • Java Developers can easily develop AJAX based web apps without learning JavaScript.
  • JavaScript generated by GWT is browser independent. So it saves the headache of supporting multiple browsers.
  • Coding in Java increases the testability of source code since Java is type-based language. GWT also provides JUnit integration for writing test cases for client side code.
  • GWT helps manage browser back button easily which is usually ignored in AJAX web apps.
  • And above all.. DEBUGGING. Client side Java code can be debugged using any Java debugger such as Eclipse, Netbeans etc. Once the developer is sure that client Java code is working fine, then it can be converted to JavaScript.
  • To support debugging, GWT supports 2 browsing modes. Hosted mode and web mode. In hosted mode, a special browser shipped with GWT is used to running client code as Java (i.e. without conversion to JavaScript). In web mode, any browser can be used and compiled JavaScript is run. It also provides scripts to run hosted mode.
  • How to exchange data with client side? GWT helps here by serializing data b/w client and server side using GWT-RPC. In simple words, the server side code creates a Java object of client side Java class (which has been translated and equivalent JavaScript code also exists on client side). GWT serializes the object and populates the equivalent JavaScript code on client side. Diagram... The serializable classes can be any primitive Java type, their wrappers, String, Date, class implementing IsSerializable interface and Arrays of objects of serializable classes (including Arrays of Arrays). Note: GWT-RPC is tailored RPC protocol for communication b/w Java and JavaScript. It should not be confused with standard RPC.
Cons:

  • Java 1.5 or above are not supports on client side code. Hence user can't use features like annotations, generics in client side code. This doesn't mean that you can't use Java 5.0 or 6.0 JDK. Only the source code need to comply with JDK 1.4.2.
  • CSS is used to styling so user still got to play around CSS. This is also good from Java code point of view as style information is not getting deeply hard coded in Java. Only style names are coded in Java. These styles are defined in CSS. GWT provides default styles for most of the widgets.
  • No support for other languages. But people are working on it. Find out more...
http://www.gwtsite.com/?m=200605&paged=2
http://www.gwtpowered.org/#Resources
Google Project Search with label GWT

Overall GWT materializes a great idea. For Java developers, its a great gift from Google. For guys from non-Java background, it will be hard to use and play around initially. Just a bunch of scripts and mainly 3 jars to play around with.
  • gwt-user.jar - While coding in Java and hosted mode.
  • gwt-dev-{OS_NAME}.jar - Debugging in hosted mode.
  • gwt-servlet.jar - To be used in web app container as some client side Java code is also used on server side.
Useful Links:
Documentation
FAQs

No comments: