Cephi Systems Software and Contract Services

10May/112

JavaScript from Java: Google Web Toolkit – GWT

Programming for the web is a bit like creating a Frankenstein monster. It is an amalgamation of different technologies that weren’t always created to work together. It reminds me of Marry Shelly’s shambling monstrosity in that it is composed of seemingly unrelated parts, crudely sewn together to create something that ends up working somehow.

I imagine if web programming was reimagined and reinvented today there would be one language encompassing all the functionality of HTML, CSS, XML, JavaScript, and PHP/Ruby. You could even throw in C#/Java (or your favorite high level language), and some SQL, so you could do everything with one language.

All this will probably only happen in some dystopian future sometime after the English language is reengineered to be more efficient, consistent, and structured. That would be doubleplusgood, no?

Well enough philosophizing and on to some Google Web Toolkit goodness… I guess I could have titled this article “Google Web Toolkit: So you know some Java and you want to do some client-side web programming?”

Google Web Toolkit (GWT) is a set of development tools that includes a GUI designer for creating Ajax applications (client-side, interactive web applications than run on a browser). GWT allows you to write a program in Java and then compile them into a combination of JavaScript, HTML, and CSS. GWT is compatible with all the major browsers and is available as a stand-alone SDK or as a plug-in for Eclipse. I used the Eclipse plug-in.

I am not here to evangelize GWT, but rather to provide a Java developer’s initial opinion on and experience with the technology.

If you have some experience with Java, one nice thing about GWT is that you don’t need to learn JavaScript to produce a client-side web applications. The calculator application I wrote (see link at the bottom) required no use of JavaScript whatsoever on my part. The compiler did all the work for me.

GWT has the advantage over Flash in that GWT just requires a web browser, no plug-ins needed. So far the apps I have created with GWT have worked great on all the mobile devices I tested them on. Flash does not work on iOS, and has mixed results on Android.

Personally, I find that I can develop client side applications a lot quicker in GWT than in HTML/CSS/JavaScript. Normally you would create buttons, input boxes, and labels in HTML, format them for appearance and graphical behavior in CSS, then do some simple programming for the functionality of the application in JavaScript. The nice thing about GWT you can do most of this all in one place, in one language. You can then test and compile your application in the IDE, and it is pretty easy to deploy all the files to your server.

The SDK generates HTML and CSS pages for you but the HTML page requires a little configuring. Also to include any fancy formatting you have to modify the CSS page. For my calculator app I just changed a couple of titles and included a division to specify where to insert the app on the page with id="GWTCalcGoesHere". Google’s tutorial explains how to do all this.

On the negative side, I imagine that GWT can be likened to Dreamweaver (or a high level programming language) wherein the code produced is typically less compact and efficient than code written manually in the underlying technology. How significant the difference is, I don’t know. As with every programming technology there is a tradeoff between development time and cost vs. performance of the end product.

If you are already good at JavaScript (and enjoy using it) I would say stay with JavaScript. If you are good with Java and you want to write some client-side apps without fooling around with a lot of HTML, and JavaScript, GWT may be worth your time checking out.

To get started with GWT I recommend visiting Google’s GWT page, installing the software, and doing their StockWatcher tutorial. You can skip the CSS steps if you are not interested in making it look pretty. It only took me a couple of hours to get GWT installed, read the introductions, and do the tutorial. Then it took a few more hours to get comfortable with the libraries, and write a couple of apps. Assuming you developed a fair proficiency with Java, learning GWT should be pretty easy.

Although the bulk of the libraries I have worked with are from GWT and not JRE, GWT does a good job of keeping things Java-like so it is easy to find the method names you are looking for. The syntax is the same and for the simple projects I worked on it pretty much feels like you are writing a Java app when working with GWT. The GWT online documentation even closely resembles the Oracle API documentation for Java, so there is no new learning curve. I do wish it included more code examples but this can be said for any programming language’s online documentation.

(Google, if you are reading this I would be happy to write billions of code snippets for you at a highly affordable price.)

So below is the link to the simple calculator application and source code I wrote using the GWT plug-in for Eclipse:

GWT Calcualtor

I wouldn’t look at this as a shining example of great program construction, but rather a peek into a little of what GWT can do. Overall I found GWT to be enjoyable to use.

Comments (2) Trackbacks (2)
  1. can GWT be outputted to a JSP?

  2. If you are asking if you can use the two together, like using GWT as a front end for JSP, the answer is yes you can: Link : Example

    If you are asking if you can create a JSP page with the GWT development tools, the answer is no.

    Enjoy!


Leave a comment