Wednesday, July 15, 2009

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,PopupListener,
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 appear 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 RemoteServiceServletextends 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.
 
Your Ad Here ]]>