Вы находитесь на странице: 1из 9

Google Web Toolkit – An Overview

The Google Web Toolkit (GWT) is a revolutionary way to build Asynchronous


JavaScript and XML (AJAX) applications that are comparable in responsiveness and
look and feel to desktop applications. Google Web Toolkit (GWT) is an open source Java
development framework that lets you escape the matrix of technologies that make writing
AJAX applications so difficult and error prone. With GWT, you can develop and debug
AJAX applications in the Java language using the Java development tools of your choice.
On deployment, the GWT compiler translates your Java application to browser-compliant
JavaScript and HTML

How is GWT different from other Frameworks?


GWT provides a set of ready-to-use user interface widgets that you can immediately
utilize to create new applications. It also provides a simple way to create innovative
widgets by combining the existing ones. You can use the Eclipse IDE to create, debug,
and unit-test your AJAX applications. You can build RPC services to provide certain
functionalities that can be accessed asynchronously from your web applications easily
using the GWT RPC framework. GWT enables you to integrate easily with servers
written in other languages, so you can quickly enhance your applications to provide a
much better user experience by utilizing the AJAX framework. GWT has the Java-to-
JavaScript compiler to distill your application into a set of JavaScript and HTML files
that you can serve with any web server. This gives us a great feature browser
compatibility

GWT Architecture
There are four major components with which the GWT is built. They are

• a Java-to-JavaScript compiler
• a "hosted" web browser
• two Java class libraries (one the JAVA API and another GWT API)

GWT Java-to-JavaScript Compiler

You use the GWT compiler to compile your GWT applications to JavaScript. The
application can then be deployed to a web container. This is referred to as running in web
mode. When you click on the Compile/Browse button, the Java code for the project is
compiled by the Java-to-JavaScript compiler into pure HTML and JavaScript. The
resulting artifacts are copied automatically to the Project/www folder.

GWT Hosted Web Browser

This enables you to run and execute your GWT applications as Java in the Java Virtual
Machine (JVM) without compiling to JavaScript first. This is referred to as running in
hosted mode. GWT accomplishes this by embedding a special SWT browser control that
contains hooks into the JVM. This special browser utilizes an Internet Explorer control
on Windows or a Mozilla control on Linux. When you run the Project, the embedded
SWT browser is what you see displaying the application.

JRE emulation library

This contains JavaScript implementations of most of the widely used classes of the
java.lang and java.util packages from the Java standard class library. Only some of the
commonly used classes from these two packages are supported. None of the other Java
packages in the JDK are currently part of this emulation library. These are the only
classes that can be used by you for the client side of the AJAX application. You are of
course free to use the entire Java class library for the server-side implementation. The
Java code in the project is compiled into JavaScript using this emulation library

GWT Web UI class library

This provides a set of custom interfaces and classes that enable you to create various
widgets such as buttons, text boxes, images, and text. GWT ships with most of the
widgets commonly used in web applications. This is the class library that provides the
Java widgets.

• Home
• SCJP Books
• New to SCJP?
• SCJP 1.4 or SCJP 1.5
• Objectives
• Articles
• Mock Exams
• Tutorials

SCJP 1.6

• Home
• What is New in SCJP 1.6?
• SCJP Books
• New to SCJP?
• Objectives
• Articles
• Mock Exams
• Tutorials
• NavigableSet
• NavigableMap
• GarbageCollection
• Console
• Finalize Method
• scjp 1.4 mock - 1
• scjp 1.4 mock - 2
• scjp 1.4 mock - 3
• scjp 1.4 mock - 4
• scjp 1.4 mock - 5
• scjp 1.4 mock - 6
• scjp 1.4 mock - 7
• scjp 1.4 mock - 8
• scjp 1.4 mock - 9
• scjp 1.4 mock - 10
• scjp 1.4 mock - 11
• scjp 1.4 mock - 12
• scjp 1.4 mock - 13
• scjp 1.4 mock - 14
• scjp 1.4 mock - 15
• scjp 1.4 mock - 16
• scjp 1.4 mock - 17
• scjp 1.4 mock - 18
• scjp 1.4 mock - 19
• scjp 1.4 mock - 20
• scjp 1.4 mock - 21

SCWCD 5.0

• SCWCD 5.0 Home


• Difference 1.4 and 5.0
• SCWCD 5.0 Book
• Mock Exams
• Mock Exam - 1
• Mock Exam - 2
• Mock Exam - 3
• Mock Exam - 4
• Mock Exam - 5
• Mock Exam - 6
• Mock Exam - 7

SCBCD 5.0

• Home
• Objectives
• Mock Exams
• Objective - 1
• Mock Exam - 1
• Mock Exam - 2
• Mock Exam - 3
• Mock Exam - 4

SCEA

• Home
• SCEA Books
• Objectives
• Mock Exams
• Mock Exam - 1
• Mock Exam - 2
• Mock Exam - 3
• Mock Exam - 4
• Mock Exam - 5
• Mock Exam - 6
• Mock Exam - 7
• Mock Exam - 8
• Mock Exam - 9
• Mock Exam - 10
• Mock Exam - 11

SCJA

• Home
• Objectives
• Mock Exams
• Mock Exams - 1
• Mock Exams - 2
• Mock Exams - 3
• Mock Exams - 4
• Mock Exams - 5
• Mock Exams - 6
• Mock Exams - 7
• Mock Exams - 8

Feeds

• Articles
• Tips

Cash For Mobile Phones you no longer need


Submit Your Blog Feedback Request Article Print Email
Looking for article writers, if you are interested contact us at krishnas@javabeat.net

Google Web ToolKit(GWT)


Google Web Toolkit Features
• User Interface

GWT provides the users with a rich content to develop UI, widgets are the basic
components provided which includes buttons, text boxes, etc. In addition to this
we have Panels, Tabs, HTMl elements.

• Remote Procedure Calls

GWT is built in such a way that all the classes are serializable and the framework
is structured to support RPCs with Servers

• Ultra debugging:

As the code is compiled by JVM before the run time, it ease the work of
debugging and error fixing. High end IDEs like Eclipse can assist in this.

• Browser compatible:

Your GWT applications automatically support IE, Firefox, Mozilla, Safari, and
Opera with no browser detection or special-casing within your code in most cases.

• Internationalization:

The set of APIs available for Internationalization is very well synchronized with
the user class structure which makes the implementation easier.

• Interoperability

We can add our own JavaScript in the Java source code using our JavaScript
Native Interface (JSNI), which gives a broad area for implementing the business.

Deploying GWT Applications


• Hosted mode - In hosted mode, the application is run as Java bytecode in the Java
Virtual Machine (JVM). The code is mere java code, and all the debugging and
exception handling are same. This ease the development process when compared
to other frameworks, where javascript compilation is a big headache.

• Web mode - In this mode, the application is run as Javascript and HTML, there
will be one boot strap js called gwt.js, which kick starts the thread.
GWT Interview Questions
What is Google Web Toolkit?

Google Web Toolkit (GWT) is an open source Java development framework that lets you
escape the matrix of technologies that make writing AJAX applications so difficult and
error prone. With GWT, you can develop and debug AJAX applications in the Java
language using the Java development tools of your choice. When you deploy your
application to production, the GWT compiler translates your Java application to browser-
compliant JavaScript and HTML.

Here's the GWT development cycle:

Use your favorite Java IDE to write and debug an application in the Java language, using
as many (or as few) GWT libraries as you find useful.
Use GWT's Java-to-JavaScript compiler to distill your application into a set of JavaScript
and HTML files that you can serve with any web server.
Confirm that your application works in each browser that you want to support, which
usually takes no additional work.

Write a Sample GWT programm ?

public class Slicr implements EntryPoint {

public void onModuleLoad() {


final Button button = new Button("Click me");
final Label label = new Label();
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if (label.getText().equals(""))
label.setText("Hello World!");
else
label.setText("");
}
});
RootPanel.get("slot1").add(button);
RootPanel.get("slot2").add(label);
}
}

What are the different listeners in GWT ?

Here is the list of listeners HistoryListener,Changes to Browser


History,WindowCloseListener,WindowResizeListener,ChangeListener,ClickListener,
FormHandler,FocusListener,KeyBoardListener,LoadListener,MouseListener,PopupListe
ner,
ScrollListener,TableListener,TabListener,TreeListener
More about listeners

Why doesn't GWT provide a synchronous server connection option?

GWT's network operations are all asynchronous, or non-blocking. That is, they return
immediately as soon as called, and require the user to use a callback method to handle the
results when they are eventually returned from the server. Though in some cases
asynchronous operators are less convenient to use than synchronous operators, GWT
does not provide synchronous operators.

The reason is that most browsers' JavaScript engines are single-threaded. As a result,
blocking on a call to XMLHTTPRequest also blocks the UI thread, making the browser
appears to freeze for the duration of the connection to the server. Some browsers provide
a way around this, but there is no universal solution. GWT does not implement a
synchronous network connection because to do so would be to introduce a feature that
does not work on all browsers, violating GWT's commitment to no-compromise, cross-
browser AJAX. It would also introduce complexity for developers, who would have to
maintain two different versions of their communications code in order to handle all
browsers.

What is AsyncCallback Interface?

public interface AsyncCallbackThe primary interface a caller must implement to receive


a response from a remote procedure call.

If an RPC is successful, then onSuccess(Object) is called, otherwise


onFailure(Throwable) is called.

Each callable asynchronous method corresponds to a method in the correlated service


interface. The asynchronous method always takes an AsyncCallback as its last parameter,
where T is the return type of the correlated synchronous method.

A call with a typical use of AsyncCallback might look like this:

service.getShapes(dbName, new AsyncCallback() {


public void onSuccess(Shape[] result) {
// It's always safe to downcast to the known return type.
controller.processShapes(result);
}

public void onFailure(Throwable caught) {


// Convenient way to find out which exception was thrown.
try {
throw caught;
} catch (IncompatibleRemoteServiceException e) {
// this client is not compatible with the server; cleanup and refresh the
// browser
} catch (InvocationException e) {
// the call didn't complete cleanly
} catch (ShapeException e) {
// one of the 'throws' from the original method
} catch (DbException e) {
// one of the 'throws' from the original method
} catch (Throwable e) {
// last resort -- a very unexpected exception
}
}
});

What are the language differences between web mode and hosted mode?

Typically, if your code runs as intended in hosted mode and compiles to JavaScript
without error, web mode behavior will be equivalent. Occasional different problems can
cause subtle bugs to appear in web mode that don't appear in hosted mode. Fortunately
those cases are rare.

How do I make a call to the server if I am not using GWT RPC?

The heart of AJAX is making data read/write calls to a server from the JavaScript
application running in the browser. GWT is "RPC agnostic" and has no particular
requirements about what protocol is used to issue RPC requests, or even what language
the server code is written in. Although GWT provides a library of classes that makes the
RPC communications with a J2EE server extremely easy, you are not required to use
them. Instead you can build custom HTTP requests to retrieve, for example, JSON or
XML-formatted data.

To communicate with your server from the browser without using GWT RPC:

Create a connection to the server, using the browser's XMLHTTPRequest feature.


Construct your payload according to whatever protocol you wish to use, convert it to a
string, and send it to the server over the connection.
Receive the server's response payload, and parse it according to the protocol.
You must use an asynchronous server connection.

Can I use GWT with my favorite server-side templating tool?

Yes, you are free to use GWT with any server-side templating tool.

With GWT development, your Java client code gets compiled into equivalent JavaScript
that is loaded into your host pages. The generated product is totally independent from the
server-side technology that you choose to use in your web application.

You can go ahead and use your favorite server-side templating tool and include your
template directives into your host pages along with your GWT-generated JavaScript files.
The server-side technology you're using to realize the templates is invisible to the
browser and works just as it does without your GWT modules.

What is Gwt Sever Side RemoteServiceServlet?

public class RemoteServiceServlet extends javax.servlet.http.HttpServletimplements


SerializationPolicyProvider

The servlet base class for your RPC service implementations that automatically
deserializes incoming requests from the client and serializes outgoing responses for
client/server RPCs.

General Questions:
 What are some advantages for the Model-View-Presenter pattern?

 How can you test a GWT application?


Use junit and selenium test cases.
 Describe what a GWT generator does ?

 What are some benefits of using CssResource, ImageResource, TextResource, etc

• Serialization and de-serialization. What is required of a user defined class for it to


be serializable?

Answer : IsSerializable interface should be used

• Event handling. Describe how an event bus is used and implemented.

• Describe how one module can inherit or use members from another GWT
module.

Вам также может понравиться