concept Java in category gwt

appears as: Java, Java
GWT in Action

This is an excerpt from Manning's book GWT in Action.

But what is GWT? GWT isn’t a “way,” or a framework, or a language. It’s a toolkit. It’s a set of tools that provide the means to easily write sophisticated and reliable Ajax applications using Java. It’s not meant to take advantage of the Java runtime, but instead it makes use of the Java language and existing Java tooling.

So what does this mean? Oversimplifying a bit, it means that you’ll write your code in Java and then compile it to JavaScript. The obvious question is, why would you want to do that? The answers are numerous. One possible answer might be that the world contains many more skilled Java developers than seasoned JavaScript developers, but that isn’t why GWT came to be. GWT was created in order to facilitate the development of large client-side browser applications with a focus on providing a great user experience, and its creators felt that the Java universe was a good fit to accomplish that goal.

But the ability to write your code in Java isn’t the only reason to adopt GWT; it also comes with a lot of bling: things like a full widget set, flexible RPC support, built-in internationalization, a template language, obfuscation, minification, image bundling, integration with server-side persistence, and more. And beyond the bling GWT comes with all of the freebies, too. We aren’t talking about T-shirts; we’re talking about open source libraries like PlayN (http://code.google.com/p/playn/). PlayN is a gaming engine, the same one that Angry Birds Chrome uses.[1]

A typical GWT application consists of client-side code written in Java and server-side code written in any language you like. One option for the server side is to use Java code and link to the client via GWT-RPC; other options include using GWT’s Request-Factory approach, or have normal Java servlets, or PHP code, or you choose. As you’ll see, GWT is remarkably flexible.

Any code that’s compiled to JavaScript needs to be written in the subset of Java that GWT understands. This restriction is common sense if you take a moment to think it through: you can only use those parts of Java that make sense in a browser context (for example, currently most of the file aspects of java.io aren’t available because browsers can’t, pre-HTML5, access the filesystem).

GWT in Practice

This is an excerpt from Manning's book GWT in Practice.

The GWT compiler is the fulcrum of GWT. The entire approach GWT takes, encapsulating browser differences and compiling JavaScript from Java, is made possible by the design and architecture of the compiler. Because of the importance of the GWT compiler and its central role in virtually every aspect of GWT projects, we need to take a good look at the compiler here; we���ll come back to it and fill in other details throughout the book.

The GWT compiler compiles Java into JavaScript, but it���s important to understand that the compiler doesn���t compile Java the same way javac does. The GWT compiler is really a Java source to JavaScript source translator.

JSNI is required any time you want to call into native JavaScript from Java, or vice-versa, so you need to understand it when working with any existing JavaScript or when tweaking display parameters beyond the exposure of the GWT browser abstraction. The GWT documentation notes that JSNI can be thought of as the “web equivalent of inline assembly code.” This goes back to the browser-as-virtual-machine idea that GWT embraces.

Now we have the Java interface for DragObserver and methods for adding observers to and removing them from the DragAndDrop class.