Google Web Toolkit Framework

Introduction

The Google Web Toolkit Framework (also commonly known as GWT) is a JAVA framework that provides developers with powerful intuitive tools that are extensively used to create browser-based web applications. The name Google Web ToolKit comes from the fact that a lot of Google applications have been made adhering to the structure of this framework. Some of the big names that have used this framework include Google AdSense and Orkut.

What is Google Web Toolkit Framework?

The Google Web Toolkit Framework is mainly used to developer Rich Internet Applications (RIA). Unlike other frameworks, the GWT is used to code client-side applications. GWT allows developers to code in JAVA as well as JAVA Script. As the framework is robust, it allows users to build heavy applications that can sustain heavy loads. It is a cross-browser framework that develops JavaScript for every browser that the application is run on.

Why use GWT?

The Google Web Toolkit has a lot of advantages. Firstly, it provides support to plugins like Junit and Maven. The language construct is properly structured such that developers do not have much problem finding their way through. It is closely related to JAVA. There are a lot of pre-coded widgets that you can easily add to your application without having to write many lines of code. Customs widgets can also be coded as required. As mentioned before, the framework produces different JavaScript for different browsers. This increases the compatibility of the applications and helps extend its reach to users.

GWT Architecture

The Google Web Toolkit framework can be broadly divided into three components namely the GWT Java to JavaScript Compiler, the JRE Emulation Library, and the GWT User interface Library.

  • GWT Java to JavaScript compiler – The GWT compiler controls all functions of the framework. It is the most important component as it is responsible for the translation of code from JAVA to JavaScript.
  • JRE Emulation Library – The library contains packages like java.lang.annotation, java.math. java.io. and java.sql. These packages are required to create almost all applications.
  • GWT UI building library – This component deals with building the interface of the application that will communicate with clients. A great deal of abstraction takes place to make the interface simple and separate the implementation from the process.

Application Using the Google Web Toolkit Framework

/*We will be building a simple application that will print out “Sample Program Successful” as an output when run successfully. We will start with the default GWT module descriptor file which has a .xml extension */

<?xml version = “1.0” encoding = “UTF - 8”>
<module rename-to = “SampleCode”>
<!--Inherit the core Web Toolkit stuff   -->
<inherits name = ‘com.google.gwt.user.User’/>

<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
 <!-- any one of the following lines. -->
 <inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
 <!-- <inherits name = 'com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name = 'com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
 <entry-point class = 'com.tutorialspoint.client.HelloWorld'/>
 <!-- Specify the paths for translatable code -->
 <source path = 'client'/>
<source path = 'shared'/>
 </module>

//Let us build the html file now

<html>
<head>
<title> Sample </title>
//We are assuming a CSS file is ready with the name as below
<link rel = “stylesheet” href = “SampleProgram.css”/>  
<script language = “javascript” src = “sampleprogram.nocache.js”>
</script>
</head>
<body>
<h1>Sample Program Successful </h1>
<p> This is a sample GWT application</p>
</body>
</html>

//Finally, we will develop the java class that will use the above files to finish the application

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;

public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
Window.alert(“Sample Program Successful”);
}
}

//On Compiling the following code, you will be able to build a simple GWT application that will print //“Sample Program Successful”.

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.