mercoledì 22 luglio 2009

How Google Web Toolkit works

With Google Web Toolkit (GWT), you write your AJAX front-end in the Java programming language which GWT then cross-compiles into optimized JavaScript that automatically works across all major browsers. During development, you can iterate quickly in the same "edit - refresh - view" cycle you're accustomed to with JavaScript, with the added benefit of being able to debug and step through your Java code line by line. When you're ready to deploy, GWT compiles your Java source code into optimized, standalone JavaScript files. Easily build one widget for an existing web page or an entire application using Google Web Toolkit.

Write AJAX apps in the Java language, then compile to optimized JavaScript

Unlike JavaScript minifiers that work only at a textual level, the GWT compiler performs comprehensive static analysis and optimizations across your entire GWT codebase, often producing JavaScript that loads and executes faster than equivalent handwritten JavaScript. For example, the GWT compiler safely eliminates dead code -- aggressively pruning unused classes, methods, fields, and even method parameters -- to ensure that your compiled script is the smallest it can possibly be. Another example: the GWT compiler selectively inlines methods, eliminating the performance overhead of method calls.

Cross-compilation affords you the maintainable abstractions and modularity you need for development without incurring a runtime performance penalty. Learn more

Development Workflow

Edit Java code, then view changes immediately without re-compiling

During development, view code changes immediately using GWT's hosted mode browser. No need for compiling to JavaScript or deploying to a server. Just make your changes and click "Refresh" in the hosted mode browser.

Step through live AJAX code with your Java debugger

In production, your code is compiled to plain JavaScript, but at development time it runs as bytecode in the Java virtual machine. That means when your code performs an action like handling a mouse event, you get normal, full-featured Java debugging. Anything your Java debugger can do applies to your GWT code, too, so naturally things like breakpoints and single-stepping are all available. Learn more

Compile and deploy optimized, cross-browser JavaScript

When you're ready to deploy, GWT compiles your Java code into plain, stand-alone JavaScript files that can be served from any web server. In addition, GWT applications automatically support IE, Firefox, Mozilla, Safari, and Opera with no browser detection or special-casing scattered throughout your code. You write the same code once, and GWT transforms it into the most efficient JavaScript for each user's particular browser. Learn more

Tip: If you are an Eclipse user, you may find the Google Plugin for Eclipse useful.

Features

Communicate with your server through really simple RPC

GWT supports an open-ended set of transfer protocols such as JSON and XML, but GWT RPC makes all-Java communications particularly easy and efficient. Similarly to traditional Java RMI, you simply create an interface that specifies remote methods you'd like to be able to call. When you call a remote method from the browser, GWT RPC will automatically serialize the arguments, invoke the proper method on the server, then deserialize the return value for your client code. GWT RPC is quite sophisticated, too. It can handle polymorphic class hierarchies, object graph cycles, and you can even throw exceptions across the wire. Learn more

Optimize the JavaScript script downloads based on user profile

Deferred binding is a feature of GWT that generates many versions of your compiled code, only one of which needs to be loaded by a particular client during bootstrapping at runtime. Each version is generated on a per browser basis, along with any other axis that your application defines or uses. For example, if you were to internationalize your application using GWT's Internationalization module, the GWT compiler would generate versions of your application per browser environment, such as "Firefox in English", "Firefox in French", "Internet Explorer in English", etc... As a result, the deployed JavaScript code is compact and quicker to download than if you coded if/then statements in JavaScript. Learn more

Reuse UI components across projects

Create reusable Widgets by compositing other Widgets, then easily lay them out automatically in Panels. The GWT Showcase application provides an overview of the various UI features in GWT. Want to reuse your Widget in another project? Simple package it up for others to use in a JAR file. Learn more

Use other JavaScript libraries and native JavaScript code

If GWT's class library doesn't meet your needs, you can mix handwritten JavaScript in your Java source code using JavaScript Native Interface (JSNI). With GWT 1.5, it is now possible to subclass the GWT JavaScriptObject (JSO) class to create Java "class overlays" onto arbitrary JavaScript objects. Thus, you can get the benefits of modeling JS objects as proper Java types (e.g. code completion, refactoring, inlining) without any additional memory or speed overhead. This capability makes it possible to use JSON structures optimally. Learn more

Easily support the browser's back button and history

No, AJAX applications don't need to break the browser's back button. GWT lets you make your site more usable by easily adding state to the browser's back button history. Learn more

Localize applications efficiently

Easily create efficient internationalized applications and libraries using GWT's powerful deferred binding techniques. In addition, as of 1.5 the standard GWT widgets support bi-directionality. Learn more

Be productive with your choice of development tools

Because GWT uses Java, you can use all of your favorite Java development tools (Eclipse, IntelliJ, JProfiler, JUnit) for your AJAX development. This allows a web developer to harness the productivity gains of automated Java refactoring and code prompting/completion. In addition, static type checking in the Java language enables developers to catch a class of JavaScript bugs (typos, type mismatches) when writing code rather than at runtime, boosting productivity while reducing errors. No more user discovered accidental var assignments. Finally, you can take advantage of Java-based OO designs patterns and abstractions that are easy to understand and maintain without your user incurring any runtime performance costs thanks to the compiler optimizations.

Test your code with JUnit

GWT's direct integration with JUnit lets you unit test both in a debugger and in a browser...and you can even unit test asynchronous RPCs. Learn more

Extend or contribute - Google Web Toolkit is open source software

All of the code for GWT is available under the Apache 2.0 license. If you are interested in contributing, please visit Making GWT Better.

Nessun commento: