Compare hotel prices and find the best deal - HotelsCombined.com

Saturday, April 18, 2015

GWT Interview questions

Why GWT?

Use Java for creating Ajax applications
No need to worry about browser dependencies, it works in all the browsers.
debugging UI is easy
UIBinder - useful for designing the GUI using XML format ( you can mix HTML and GWT Widgets)
Code Splitting is easy

Important modules in GWT?

GWT Compiler
JRE Emulation library
Hosted Mode ( Run as java)
Web Mode ( Run as JavaScript)

    What is GWT Compiler?

    GWT Compiler used to convert the client side Java code to Javascript at the time of building the source files.

    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.
    GWT - Java Emulation library?
        
    Google Web Toolkit includes a library that emulates a subset of the Java run-time library. The list below shows the set of JRE packages, types and methods that GWT can translate automatically. Note that in some cases, only a subset of methods is supported for a given type.

        java.lang
        java.lang.annotation
        java.math
        java.io
        java.sql
        java.util
        java.util.logging


    Bootstrap process:

    HTML
      |
    nocache.js ( Bootstrap javascript file )
      |
      |->( Loads the browser specific files)
      |
    module.xml ( *.gwt.xml )
      |
      |->( which loads the entry point class )
      |
    onModuleLoad() method
      |
      |
      |
    Loads the application

    HTML
              -- > .nocache.js (bootstrap JavaScript file)
              -- > Which loads the browser specific files (Permutation javascript file)
    Module.xml
             -- > Basic inherits (required modules)
             -- >Entry point class (onModuleLoad () method)
             -- > cross site linker (useful for code splitting)


    GWT Panels:

    RootPanel is the top level panel.

    For layout the page, we could use following layout panels, finally we need to add all those layout panels in RootPanel.


    DockLayoutPanel

    SplitLayoutPanel

    StackLayoutPanel

    TabLayoutPanel



    Use below panels inside the Layout panels for holding the widgets.

    HorizontalPanel

    VerticalPanel ( Prefer using FlowPanel )



    Code Splitting:

    Using GWT Way:

            GWT.runAsync(new RunAsyncCallback() {
              public void onFailure(Throwable caught) {
                Window.alert("Code download failed");
              }
              public void onSuccess() {
                Window.alert("Hello, AJAX");
              }
            });


    Using GWTP Way (just with Annotations in Presenter Proxy)
            @ProxyStandard – Initial loading
            @ProxyCodeSplitting – On demand loading

    GWT Linkers:
                 IFrameLinker – Default
                    XSLinker – For cross site support
                    SingleScriptLinker
                   

    Refer following URL for detailed description

    http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html


    How to create custom widgets in GWT?

    Create a class that should extends Composite class of GWT.
    Inside the constructor you can write you logic to create a widget and call the initWidget method().

    Then you can use this class in anywhere in the application and add this widget in any panels.
    Refer following URL

    https://developers.google.com/web-toolkit/doc/latest/DevGuideUiCustomWidgets


    What is the advantage of using Cell Widgets in GWT and Why?

    Why we need to use CellTable instead FlexTable or GRID?

    CellTable gives the following features

    Pagination
    Default Header and Footer - Using DataGrid
    Column Sorting
    Column Width setting

    You can even create Custom Cells


    What is AsyncDataProvider in GWT cell widgets? 

    When you want to display dynamic data or a range of data, not just a static list, then we should use AsyncDataProvider.

    What is the use of ValueUpdater vs FieldUpdater in Cell Widgets?


    GWT ClientBundle: 

    In GWT we can use ClientBundle to load all the images and CSS files in one single file and use it anywhere in the application. It provides flexible way to get the resources.

    1. It creates a single image from the collection of images at compile time to reduce the image size.
    2. Enable more aggressive caching headers for program resources. It will go to server for every-time to get the images.
    3.Eliminate mismatches between physical file names and constants in Java code by performing consistency checks during the compile

    Examples

    To use ClientBundle, add an inherits tag to your gwt.xml file:
     
     
    If you write this interface:
     
    public interface MyResources extends ClientBundle {
      public static final MyResources INSTANCE =  GWT.create(MyResources.class);
    
      @Source("my.css")
      public CssResource css();
    
      @Source("config.xml")
      public TextResource initialConfiguration();
    
      @Source("manual.pdf")
      public DataResource ownersManual();
    }

    You can then say: 
     
     // Inject the contents of the CSS file
      MyResources.INSTANCE.css().ensureInjected();
    
      // Display the manual file in an iframe
      new Frame(MyResources.INSTANCE.ownersManual().getURL());
     
     

    Server side communication:

    -- > Using GWT RPC
          To user GWT RPC we need to create couple of interfaces and one implementation class.
          1. Synchronous interface
          2. Asynchronous interface
          3. Implementation class implements Synchronous interface

          Why two interfaces?
          GWT Supports non blocking calls, it means call from client side to server side is non blocking. It just call the server side method and proceed with remaining lines.

          So, how are we going to get the response from server side?
           For this purpose only GWT has one Asynchronous interface which has one parameter called AsyncCallBack, using this callback object it will call the client side code once the server completed the execution.
           So basically all the calls to server side method will have two call back methods
           onSuccess()
           onFailure()

           If the server side method executed properly then onSuccess() method will be called otherwise onFailure() method will be called, so based on this we can proceed with our functionality.




    -- > Using RequestBuilder

              To use RequestBuilder we need to inherit HTTP Module in module.xml file
             


    --> Using Command Pattern (GWTP Dispatcher)
          We could use GWTP framework, which is basically a MVP based framework supports lot of good features like.
    • Dependency injection through GIN and Guice;
    • Simple but powerful history management mechanism;
    • Support for nested presenters;
    • Lazy instantiation for presenter and view;
    • Effortless and efficient code splitting;
    • Integrated command pattern supporting undo/redo.

    GWT Serialization:

                    -- >Using GWT IsSerializable OR Java Serializable

                   Please find below couple of good links related to this topic

    http://stackoverflow.com/questions/3065135/what-is-the-purpose-of-the-isserializable-interface-in-gwt-regarding-the-rpc-me

    https://groups.google.com/forum/#!topic/gwt-dispatch/Yl-tsNgU_GU

    What are some advantages for the Model-View-Presenter pattern?

    What is Entry-point class in GWT and how to configure this? 

            Entry point class in GWT is like normal main class in Java application. So this is the class going to be called on application startup.

    We need to configure this class in module.XML file 

    It has a method called onModuleLoad(), this method will be called first when we start any GWT based application.  

    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.


    GWT RPC vs GWT RequestBuilder ( for server side communication )

              1. When we use GWT RPC we dont need to handle Serialization / Deserialization of the request.
              2. When we use RequestBuilder we need to handle Serialization / Deserialization of the request/response.


    What is the use of UIBInder in GWT and why we should use UIBinder? 

    How can you test a GWT application?

    What is deferred binding in GWT? 

    Describe what a GWT generator does
        Refer the following URL
        http://stackoverflow.com/questions/3298317/what-is-the-use-gwt-generator

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

    How does GWT app work? (compiling to JavaScript, cross-browser support, bootstrapping script, etc.)

    When would you NOT use GWT? (rather general and open-ended question, but it demonstrates if developer is really into this technology) 
        Follow-up question: What GWT alternatives would you consider?

    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

    Describe server-side development with GWT.

    Did you use DI framework with GWT?
            GUICE - For server side dependency injection
            GIN - Client side dependency injection

    What does make MVP better fit for GWT than general MVC?

    Serialization and Un-serialization. What is required of a user defined class for it to be serializable?

           All we need to do is create a class which implements GWT IsSerializable or Java Serializable interface.


    IsSerializable Vs Serializable:

    Both are acceptable in GWT to make a class serializable.

    When you use Normal java Serializable you need to take care all the serialized classes are available in the Serialization policy file or not.

    But when you use GWT IsSerializable, you don't need to worry about Serialization policy file.

    So, if your class is only used by GWT application, better we can go for GWT IsSerializable.

    If your model class is used by more than one Application then better use Java Serializable.


    Event handling. 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
       
        Refer the following link for more detailed information.
            http://stackoverflow.com/questions/998621/gwt-custom-event-handler

    Describe how one module can inherit or use members from another GWT module.
        http://stackoverflow.com/questions/890352/gwt-module-xml-how-to-redefine-and-use-more-than-one-user-agent
        http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2df682d31e50511e/b42924ca8e40e559
        stackoverflow.com/questions/3292671/multiple-entry-points-in-gwt
        http://stackoverflow.com/questions/332285/large-apps-in-gwt-one-module-or-several