Friday, July 3, 2009

The GWT Compiler

The GWT compiler converts Java source code into JavaScript. The GWT compiler supports most of the Java language and emulates a subset of the Java runtime library.
Language support
As of GWT version 1.4, the GWT compiler can compile source code that is compatible with J2SE 1.4.2 or older.
The GWT compiler:
supports all intrinsic types (byte, char, short, int, float, double, Object, String) and arrays. Please note that since there is no 64-bit integral type in JavaScript, Java variables of type long are mapped to JavaScript double-precision floating point values. Try to use int variables whenever possible.
supports Java Exception handling. try, catch, finally and user defined exceptions are supported. Throwable.getStackTrace() is only supported in “Hosted Mode”.
parses Java assert statements, but does not generate JavaScript code for them
does not support Reflection or dynamic class loading.
does not support object finalization during garbage collection
does not support Strict Floating Point (strictfp keyword) and can’t ensure any particular degree of floating point precision in translated code.
does not support Java Serialization.
Runtime Library Emulation
GWT provides a JRE emulation library. This library does NOT emulate all the J2SE and J2EE classes.
The GWT JRE emulation library supports some classes from java.lang and java.util packages. Find out which classes are supported here
Java regular expressions aren’t completely supported in GWT. If you are going to use regular expressions in your GWT application, you need to ensure that you only use Java regular expressions that have the same meaning in JavaScript.
Find out more about Java regular expressionsFind out more about JavaScript regular expressions
The GWT JRE emulation library does not support Java Serialization. In its stead however, GWT has and RPC facility that provides automatic object serialization. This RPC facility allows client-side code to make remote method calls and pass GWT serialized objects as parameters.
To find out more about the GWT compiler check out this article.
Client Side Code
GWT web applications are made up of two distinct pieces. The piece of your application that is sent across the network to a user, where it runs as JavaScript inside of a web browser, is referred to as client-side code. When writing client-side code it is important to keep in mind that this code will ultimately be turned into JavaScript. So make sure to only use libraries and Java language constructs that can be translated.
Server Side Code
The piece of your application that runs on a server computer is referred to as server-side code. Your GWT application might need to interact with your server, e.g. to load or save some data. In order to do this, the application makes a client-side request (from the browser) using GWT’s RPC mechanism. While processing the RPC call, server-side code is being executed. In GWT, client-side code compilation is not dependent on server-side code. As a result, you’re server-side code does not have any of the limitations that are imposed on the client-side code and you are free to choose whatever technology you want to use in your server-side code.

No comments: