GWT Interview Questions and Answers

by Rupa.R, on Sep 10, 2022 4:29:49 PM

Interview Questions (11)

Q1. What is Google Web Toolkit (GWT)?
The Google Web Toolkit (GWT) is a toolkit to develop Ajax web application with Java. The programmer writes Java code and this code is translated into HTML and Javascript via the GWT compiler.
The compiler creates browser specific HTML and JavaScript to support all the major browsers correctly. GWT supports a standard set of UI widgets, has build in support for the browser back button and a JUnit based test framework.
GWT provides two modes:
Development Mode: allows to debug the Java code of your application directly via the standard Java debugger.
Web mode: the application is translated into HTML and Javascript code and can be deployed to a webserver.

Q2. What are the Important modules in GWT?
1.GWT Compiler
2.JRE Emulation library
3.Hosted Mode ( Run as java)
4.Web Mode ( Run as JavaScript)

Q3. Is GWT works in all the browsers? If yes why?
Yes GWT works in all the browsers because GWT compiler creates javascript code per browser and per localization.
I meant, if you configure module.xml with Firefox and IE then GWT compiler will create javascript code for both browsers seperately.
And when you load the application it first check from which browser you are opening the application and it will load the corresponding javascript.
It means GWT supports Cross browser functionality.

Q4. What are the features of GWT?
Following are the features of GWT −
1.Google Web Toolkit (GWT) is a development toolkit to create RICH Internet Application(RIA).
2.GWT provides developers option to write client side application in JAVA.
3.GWT compiles the code written in JAVA to JavaScript code.
4.Application written in GWT is cross-browser compliant. GWT automatically generates javascript code suitable for each browser.
5.GWT is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0.

Q5. What are the core components of GWT?
Following are the core components of GWT −
GWT Java to JavaScript compiler − This is the most important part of GWT which makes it a powerful tool for building RIAs. The GWT compiler is used to translate all the application code written in Java into JavaScript.
JRE Emulation library − Google Web Toolkit includes a library that emulates a subset of the Java runtime library. The list includes java.lang, java.lang.annotation, java.math, java.io, java.sql, java.util and java.util.logging.
GWT UI building library − This part of GWT consists of many subparts which includes the actual UI components, RPC support, History management, and much more.
GWT Hosted Web Browser − GWT Hosted Web Browser lets you run and execute your GWT applications in hosted mode, where your code runs as Java in the Java Virtual Machine without compiling to JavaScript.

Q6. 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.

Q7. What is the purpose of ‘source’ tag in *.gwt.xml file in GWT?
This specifies the names of source folders which GWT compiler will search for source compilation.

 Q8. What is the purpose of ‘public’ tag in *.gwt.xml file in GWT?
The public path is the place in your project where static resources referenced by your GWT module, such as CSS or images, are stored.

Q9. Which widget represents a single line text box in GWT?
TextBox widget represents a single line text box.

Q10. Which widget represents a password text box in GWT?
PasswordTextBox widget represents a text box that visually masks its input to prevent eavesdropping.

Q11. Which widget represents a multiline text box in GWT?
TextArea widget represents a text box that allows multiple lines of text to be entered.

Q12. Which widget represents a rich text editor in GWT?
RichTextArea widget represents a rich text editor that allows complex styling and formatting.

Q13. Explain bootstrap procedure for GWT application.
Following are the steps of bootstrap proceure for GWT application when a browser loads the GWT application −
Browser loads the host html page and .nocache.js file.
Browser executes the .nocache.js file’s javascript code.
.nocache.js code resolves deferred binding configuarations (for example, browser detection) and use lookup table generated by GWT compiler to locate one of the .cache.html.
.nocache.js code then creates a html hidden iframe, inserts that iframe into the host page’s DOM, and loads the .cache.html file into the same iframe.
.cache.html contains the actual program of a GWT application and once loaded in iframe shows the GWT application in the browser.

Q14. What are Modules, Entry Points and HTML Pages in GWT?
GWT applications are described as modules. A module \”modulename\” is described by a configuration file \”modulename.gwt.xml\”. Each module can define one or more Entry point classes.

An entry point is the starting point for a GWT application, similar to the main method in a standard Java program. A Java class which is an entry point must implement the interface \”com.google.gwt.core.client.EntryPoint\” which defines the method onModuleLoad().
The module is connected to a HTML page, which is called \”host page\”. The code for a GWT web application executes within this HTML document.
The HTML page can define \”div\” containers to which the GWT application can assign UI components or the GWT UI components are simply assigned to the body tag of the HTML page.

Q15. 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.

Q16. What is the purpose of the IsSerializable interface in GWT?
A user-defined class is serializable if all of the following apply:
It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
All non-final, non-transient instance fields are themselves serializable, and
As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.
One key difference though is that , for security reasons, all Serializable classes must be included in a serialization policy, which is generated at compile time, while IsSerializable classes do not have that requirement.
If your interest is purely in GWT, and you don\’t e.g. share your model classes between the web application and another application, I suggest you have your model classes/DTOs implement IsSerializable.

Q17. 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.

Q18. How GWT Navigation works?
In GWT we can handle page navigation using couple of ways.

1. Using History tokens
2. Clearing the content panel and load the new page in the content panel.

Q19. What 3d party libraries have used with GWT? Which libraries would you recommend? Why?
GUICE – for Server side dependency injection
GIN – for client side dependency injection
GWTP – Model – View – Presenter framework

Q20. Describe how an event bus is used and implemented.
Create a Classs that extends GWTEvent
Define a new handler and marker interface for the event class.
Register the event using EventBus where you implement interface( the one written inside the event class)
implement the interface method and call the event fire method

Q21. What is Module descriptor in GWT?
A module descriptor is the configuration file in the form of XML which is used to configure a GWT application. A module descriptor file extension is *.gwt.xml, where * is the name of the application and this file should reside in the project’s root.

Q22. How can we run GWT application?
Two ways of running the application:

  1. Create a war file and deploy in any app server or
  2. Run ant hosted in the command prompt. And click on the ‘Launch Default Browser’.

Q23. How to compile the GWT application?
Run ant build in the root folder of the application

  • By default gwt compiler creates optimized JS files for some browsers.

Disadvantage is it takes a lot of time to compile each change because of the permutations
Steps:

  1. Open command prompt
  2. Go to the application root folder
  3. Run command as \”ant build\”

Then you can see compile logs are coming. If you see BUILD SUCCESSFUL it means no error in your application. If BUILD FAILED it means there is an error in your application.

Topics:Interview Questions with Answers

Comments

Subscribe