This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

Feature: Programming

GWT: A new way of doing Web development

By Federico Kereki on January 15, 2008 (9:00:00 AM)

Share    Print    Comments   

Are you dazzled by the way you can drag Google Maps around or move from one place to another without having to reload the screen? Or maybe you're a fan of Gmail and its look and feel? If you want to develop Web sites with Google's signature user-friendly features but are afraid of the work involved, take a look at the Google Web Toolkit (GWT).

GWT, a tool for Web programmers, made its first public appearance in May 2006 at the JavaOne conference. It's in full development, and its current version is 1.4.61; version 1.5 is promised for Q1 2008. It's licensed under the Apache License 2.0, though some of its components are under other licenses.

Why would you use GWT?

Developing a modern, dynamic Web application can be a frustrating experience. For starters, you need to write specific code to address the many incompatibilities among browsers. Otherwise, your site might look fine in, say, Mozilla Firefox, but not work at all in Internet Explorer or Safari. Web developers usually end up spending more time on cross-testing than on the actual development of the site itself. Also, to develop interactive sites, you need to use JavaScript, a language that's powerful but lacking in modularity and testing facilities, which causes problems when creating large systems. Of course, you also have to know HTML and Cascading Style Sheets (CSS) for the Web design itself, and languages such as PHP or Java for writing Web services. Many sites require Dynamic HTML (DHTML), so you'll have to change the actual source code of the page you're seeing on the fly, and there are some compatibility issues there too. Finally, you might need to do international development for a multilanguage site -- another complication.

GWT lets you avoid these problems by allowing you to work in Java, using tools such as Eclipse or NetBeans for coding, Unified Modeling Language (UML) tools for class design, JProfiler for optimizing performance, JUnit for automated testing, and Javadoc for documentation. With these tools you can avoid common errors such as typos and type mismatches, and you can use refactoring for code quality enhancement. You can run or debug your application in hosted mode, meaning your program runs as Java code within the Java Virtual Machine (JVM), giving you access to debugging tools. You can then convert it to JavaScript and HTML and run it in Web mode, in the same way your end users would.

Note that you never have to worry about HTML or JavaScript. When GWT compiles from Java to JavaScript, it takes care of compatibility problems, so your site looks the same no matter which browser you use. GWT also greatly simplifies the use of AJAX, allowing you to easily access Web services that might or might not also be written in Java.

What does GWT include?

GWT includes four components:

  • Hosted Web browser: Allows you to test your Java application the same way end users would see it.
  • Web interface library: Lets you create and use Web browser widgets, such as labels, text boxes, and radio buttons. You do your Java programming using these widgets, and the compilation process transforms them into HTML equivalents.
  • Java emulation library: Provides JavaScript-equivalent implementations of the most common Java standard classes. (Note that not all of Java is available, and there are restrictions as to which classes you can use. It's possible that you'll have to roll your own code, should you want to use an unavailable class.)
  • Java-to-JavaScript compiler (translator): Produces the final Web code.

If you're like most programmers, you probably worry about the performance of the converted code. GWT generates ultracompact code that you can further compress and cache, so your end users can download a few dozen kilobytes of end code just once. The quality of the generated code approaches (and perhaps even surpasses) the quality of hand-written JavaScript, especially for larger projects. According to the GWT creators, version 1.5 is going to be even better. Finally, being able to avoid wasting time doing debugging in every Web browser gives you more time for application development itself, which allows you to produce more features and better applications.

Installing and using GWT

Before installing this toolkit, you should already have installed the Java Development Kit (JDK). GWT is currently oriented to working with Eclipse, and that's what Google's own developers use, so you might want to get that as well. (You can also get GWT to work with NetBeans or other common development environments.) Then go to the download site, get the latest package -- it's about 25MB in size -- and extract it by using tar jxf ../gwt-linux-1.4.61.tar.bz2. No further installation is required, and you can use GWT from any directory.

To create a new project, follow the GWT's instructions. If you're working with Eclipse, follow these instructions:

  • Create a directory for your project.
  • Create a project in the directory, using ./pathToGWT/projectCreator -eclipse MyOwnProject.
  • Create a basic empty application with ./pathToGWT/applicationCreator -eclipse MyOwnProject com.yourCompanyName.client.YourApplicationName.
  • Open Eclipse, go to File -> Import, choose Existing Projects Into Workspace, and select the directory in which you created your project.

You can now edit both the HTML and Java code, add new classes, and test your program in hosted mode. When you're satisfied with the final product, compile it (an appropriate script is generated when you create the original project) and deploy it to your Web server.


GWT is an innovative way of doing Web development. It allows Java programmers to produce Web applications, use the tools they're accustomed to, and work at a higher level, while producing modern, highly interactive Web sites.

Federico Kereki is an Uruguayan systems engineer with more than 20 years' experience developing systems, doing consulting work, and teaching at universities.

Share    Print    Comments   


on GWT: A new way of doing Web development

Note: Comments are owned by the poster. We are not responsible for their content.

GWT: A new way of doing Web development

Posted by: Anonymous [ip:] on January 15, 2008 02:47 PM
Do not forget to mention the disadvantages of the GWT. Especially in business environments it is often crucial to implement already modeled business processes. There is no support for BPEL or other business process engines. Furthermore you must always convert your complex objects on the server side to simple DAOs on the client side, as the client side only understands a small subset of the Java langauge (the subset which can be compiled into JavaScript). Descriptive Validators which are only written once, but implemented differently on client and server side are a big issue (something JSF supports very nice).

GWT is very nice to play with, unbelievable handy and really cool, if you need to deploy a web application only with Java knowledge - but it needs more time to be a good software which can be used for big business projects (however contactoffice proves one wrong, a very nice app written in GWT).


Re: GWT: A new way of doing Web development

Posted by: Anonymous [ip:] on January 16, 2008 01:30 PM
It's not entirely fair to lay these disadvantages completely at the feet of GWT. What you are describing is a disadvantage of all browser based applications, GWT or otherwise. The native languages of the browser, CSS, HTML and mostly Javascript do not have the complete feature set that a language like Java has. And to be fair to that comment, Javascript is an incredibly powerful language, it's the serialization across the HTTP wire that causes the greatest problem. But as I stated, your point is against all DOM Scripted/DHTML/AJAX chubby clients....and not just GWT.

If you buy into the browser based AJAX applications...GWT is a fantastic enterprise-level tool absolutely tailored to big business projects.


Re: GWT: A new way of doing Web development

Posted by: Anonymous [ip:] on January 16, 2008 05:59 PM
It's always easier to have your interface coupled with your server.... right? A lot of people doing development with JSF or any server generated client side technology will have a difficult time getting out of that way of thinking simply because it took quite a bit of work to get into it. Server side scripts will always be good at serving pages or generating reports but for more complex processes and tasks it doesn't make sense to do this constant state juggling between client and server. Up until now the alternative, Ajax, wasn't good for real software engineering. But now GWT lets you have decoupled clients running in a browser without the need for plugins with all the advantages of Java dev tools. And not being able to use JavaMail from a web browser is not a new restriction that came with GWT.


This story has been archived. Comments can no longer be posted.

Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya