Monday, November 22, 2010

GWT Event listeners

What is GWT Event Listeners?
Answer : GWT defines the event listeners that you can attach to a widget to monitor browser
 events. Event Listeners are just interfaces ,that you can implement on your widget.

Question : How to trap mouse click events?
Answer :  your widget must implement clickListener Interface and defines the method
 onClick(widget sender)  the code inside this method will triggered whenever user clicks on that
widget.

Question : How to Implement clickListener Interface ?
Answer : Can be implemented anonymously  like below :
          button.addClickListener(new ClickListener() {
     public void onClick(Widget sender) {
     processData(sender.getText());
     reportData(sender.getText());
      logResults();
     }
   });
Note: The button widget add methods addClickListener and attaches object
ClickListener to it.

Question : What are the disadvantages of above anonymous implementation?
Answer : code should b repeat on each object. 

Question : What are the other way of implementing listener?
answer  : Put the listener implementation in the class.

Example : Public class MainPanel extends composite implements
           ClickListener {
               private Button mybutton = new Button("Click");
               MainPanel(){
              ......
               mybutton.addClickListener(this);
               }
             public void onClick(Widget sender){
              if(sender == button){
               //Do implementation for button;
             }
           }
NOTE: Implement the listeners in container widget to handle the events of
       Contained widget.
Question : What can i do if i want add clicklistener in another link.
Answer : Simple ,
link.addClickListener(this);
if(sender == link || sender == button)
{ Do somethng this } 
Note: all Event Listener are available to all Widgets.
Question : What is composite ?
Answer : Combination of two widgets.
Question : How will you implement the keyUpActionListener in textField?
Answer : public class KeyListener 
{
TextField tf = new TextField();
tf.addKeyUpHandler(new keyUp(this));
}
--------------------------------------------------------
public class keyUp implements KeyUpHandler {
private KeyListener app ;
keyUp(KeyListener app)
{ this.app = app}
public void onKeyUp(KeyUpEvent event){
...................
}

Sunday, November 21, 2010

Interface

What is Interface?
Answer : An interface is a description of a set of methods that conforming implementing classes must have.
Note:
    1. You can’t mark an interface as final.
    2. Interface variables must be static.
    3. An Interface cannot extend anything but another interfaces.
    4. \
    Question : Can we declare a Instance Variable in an Interface ?
    Answer : NO , All variables in Interface is public static final implicitly and Explicitly.
    Example :  
                      public Interface myInterface  
                     {
                                int i = 50; /* looks like a instance variable but not */
                     }
          The actual Implementation of above code is 
                      public Interface myInterface
                    {
                             public static final int i = 50;
                    }
    Look into Following wonderful link : 



    • Question :

    Wednesday, November 17, 2010

    Collection Interview Questions.

    Question: Difference between Vector and ArrayList?
    Answer : 
                  1) Synchronization:
                             vector is synchronized and ArrayList is not.
                 2) Data Growth:
                  Both holds there contents using the Array.
                 Vector double the size of it's array.
                 ArrayList increases it's array Size by 50 percent.
    3) Default Size :
               vector: Has default size of 10.
             ArrayList : Has no default size.
    4) Iteration :
           ArrayList : Use only iterator to traverse the elements.
           Vector : can use Iterator and enumeration interface to traverse the elements.
    Question: Difference between Hashtable and HashMap ?
           1) Synchronization:
                    Hashtable : Synchronized.
                    HashMap : Not Synchronized.
           2) Null Values :
               HashTable: Does not allow null  key - values, it Does not allow duplicate values.
               HashMap : allows null key and null values.
    Detailed Explanation :
    HashMap : Allows null as key and null as value.
    if you duplicate the key value in HashMap it simply overwrites the key value.
    that means.


    case 1 :
    HashMap.put(null,null);
    HashMap.put(null,null); is allowed in HashMap.
    case 2 :
    HashMap.put("sekhar",200);
    HashMap.put("sekhar",400);
    in the above case it simply overwrites the key with new value : 400.
    case 3:
    HashMap.put(null,"Java") // is allowed in HashMap.


    Case 4 :
    HashMap.put("Java",null) // allowed in HashMap.
    HashMap.put("Java",null) // allowed in HashMap. overwrites the Key.


    HASHTABLE :
    case1 :
    Hashtable.put(null,null) // Not supports in Hashtable. but allowed in Hashmap.


    case2:
    Hashtable.put("sekhar",400);
    Hashtable.put("sekhar",300);
    Same like the HashMap it simply overwrites the Key here also.
    case 3:
    Hashtable.put(null,"MyName");
     // not allowed in Hashtable same like HashMap.
    case 4:
    Hashtable.put("Java",null) 
    //not allowed in hashtable but allows in Hashmap.


    Observation 1 : Simply, if either key or value if it is null it is not allowed in Hashtable.
    Observation 2 : No Problem key or value allowed as null in HashMap.


    Question : What is the difference between TreeMap and HashMap?


    TreeMap                                                             HashMap
    1) Cannot insert null as key                              1)cannot inset null as key.
    2) keys in TreeMap stored in sortedOrder    2)stored according to hashCode.
    Note1 : 
    TreeMap is like the Hashtable :where we cannot insert null as key.
    Hashtable does not support the null as value,but Tree Map supports that.
    Note2: 
    2) TreeMap has constructor which takes comparator and sorts the keys according 
    to that.
    Question : What is the difference between the TreeSet and HashSet ?
    Ans: TreeSet                                                                                     HashSet
    1) organize the data in a tree through use of comparator  2) organize in HashTable
    (natural Ordering)                                                                         through hashcode.
    2) Do not need to sort the elements.


    Question : What is Collection Framework hierarchy ?
    Ans : 
                     Collection[ interface ]                      MAP [ interface ]
    |---------------|--------------|                                    |
    List[ interface ]     Set[interface]            SorterdMap[ interface ]        
    |                                            |                                             |
    ArrayList, LinkedList      Hashset, Treeset           HashMap,TreeMap


    Note : ArrayList, LinkedList, HashSet,Treeset, HashMap,TreeMap are the 
    Concrete Class came from java 1.5. These are not Synchronized.


    There are historical classes like Vector,HashTable,Stack,Properties these
     present in Java 1.0 and these are synchronized.
    Question : What are class which does not suits really for serialization ?
    Ans :  In general, any class that involves native code is not really a good candidate for serialization.
    http://oreilly.com/catalog/javarmi/chapter/ch10.html


    Note: Iterator in of Behavioural Pattern.
    Note : It a best practice to implement the user defined key class as an immutable object.


    String class in designed with "FlyWeight" design Pattern.
    What are the Final Methods in String Class ?
    Ans : wait, notify,notify,getClass.


    Question : What is concurrentHashMap?
    Ans :Permits any number of concurrentReads and tunable  number of concurrent 
    Writes.
    Concurrent Package : also have 
    CopyOnWriteArrayList, CopyOnWriteArraySet.


    Example of CopyOnWriteArrayList ;

    CopyOnWriteArrayList mylist = new CopyOnWriteArrayList();
          mylist.add("sekhar");
          
          Iterator myIt = mylist.iterator();
          mylist.add("Ramu");
          
          while(myIt.hasNext()){
     System.out.println(" Value : "+myIt.next());
          }
    Above Example Does not through any Exception : like ConcurrentModification 
    Exception. but a ArrayList throws that Exception.


    NO risk of Concurrent Modification.


    Note: A TreeSet is a orderedSet which implements the SortedSet.
    Note: Iterator is Behavioural Design Pattern.



    Q. What is a list iterator?
    The java.util.ListIterator is an iterator for lists that allows the programmer to
    traverse the list in either direction (i.e.forward and or backward) and modify the
    list during iteration.



    MY-SQL Joins Tutorial

    Example of Left Join?
    Answer :
                  Table  Name : demo_people
    +------------+--------------+------+
    | name       | phone        | pid  |
    +------------+--------------+------+
    | Mr Brown   | 01225 708225 |    1 |
    | Miss Smith | 01225 899360 |    2 |
    | Mr Pullen  | 01380 724040 |    3 |
    +------------+--------------+------+
    3 rows in set (0.00 sec)
    Table Name : demo_property
    +------+------+----------------------+
    | pid  | spid | selling              |
    +------+------+----------------------+
    |    1 |    1 | Old House Farm       |
    |    3 |    2 | The Willows          |
    |    3 |    3 | Tall Trees           |
    |    3 |    4 | The Melksham Florist |
    |    4 |    5 | Dun Roamin           |
    +------+------+----------------------+
    Left Join :If I do a LEFT JOIN, I get all records that match in the same way and IN ADDITION I get an extra record for
     each unmatched record in the left table of the join - thus ensuring (in my example) that every PERSON gets a mention:
    select name, phone, selling 
    
    from demo_people left join demo_property 
    
    on demo_people.pid = demo_property.pid; 
    
    +------------+--------------+----------------------+
    
    | name       | phone        | selling              |
    
    +------------+--------------+----------------------+
    
    | Mr Brown   | 01225 708225 | Old House Farm       |
    
    | Miss Smith | 01225 899360 | NULL                 |
    
    | Mr Pullen  | 01380 724040 | The Willows          |
    
    | Mr Pullen  | 01380 724040 | Tall Trees           |
    
    | Mr Pullen  | 01380 724040 | The Melksham Florist |
    
    +------------+--------------+----------------------+

    AutoBoxing in Java

    Question : what is Auto-Boxing ?
    Answer : Auto-boxing and Auto-Unboxing enables the primitive types to be converted into 
     respective wrapper objects and the other way around.


    Question : When this feature Introduced ?
    Answer:  In Java 5.0.


    Question: Example for Auto-Boxing ?
    Answer :  with auto boxing we can write like this,
                        Integer i = 2;
                    without auto boxing the same can be done in.
                      Integer i = new Integer(2);

    Tuesday, November 16, 2010

    GWT Basics

    Question : What is GWT ?
    Answer : Google Web Tool Kit(GWT) is a open source Java Development Framework,
     use to develop Ajax(Asynchronous JavaScript and XML)  Web applications those looks
     like the desktop applications.


    Question: What are the other Frameworks which can compete the GWT framework ?
    Answer:  1) Ruby on rails
                   2) JQuery.
                   3) Flex.
                   4) Echo2.


    Question :  What are the advantages of GWT Framework ?
    Answer:
    1) True Interaction: with lots of code executed on client side, reduce server-side 
        interaction minimum.
    2) Easy to Develop : Using Java Language.
    3) Excellent IDE Support :  With Excellent Debugging Skills.
    4) Easy Integration of JavaScript: using the JSNI(Javascript Native Interface) we can 
        easily integrate the Javascript, we can integrate easily whenever we required the 
        JavaScript in GWt.
    5) Easy Integration with Hibernate.
    6) Excellent News Group  facilities.
    7) Widget Support : Ready to use excellent Widgets.
    8) Easy Integration with Server : GWT enables to integrate with server written in any    
         language.
    9) using Ajax framework : rich web application look using the AJAX framework.
    10) Good webserver Support : GWT has java-to-javascript compiler which is to distill 
         your web application into HTML and Javascript that you can server with any webserver.
    11) Great Browser Compatibility : using the above feature.
    12) Debugging in Hosted Mode.


    Question: Hurdles in GWT Framework ?
    Answer:
    1) Slow Compilation.
    2) No Support for multi-core : Compilation Process does not support the multiple Cpu's.
    3) inconvenient to use arbitrary HTML with GWT: solved by using the powerful CSS.


    Question: What is Host Mode in GWT ?
    Answer : This is enables you to run your GWT application as Java in JVM.without
    compilling to Javascript to First.This is called Host mode.


    Question: How hostmode is accomplished?
    Answer : by using SWT browser(Standard Web Tool Kit) this has hooks into JVM.
    When you run your application in hostmode, the browser which u see u'r application is
    nothing but the SWT browser.


    Question : What is Web Mode ?
    AnswerYou 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 KitchenSink project is compiled by the Java-to-JavaScript compiler into pure HTML and JavaScript.


    Explain the four main Components of GWT?
    Answer : 
                   1) GWT java - javascript compiler.
                   2) GWT hosted web browser.
                   3) JRE emulation library.
                   4) GWT web User interface Library.


    1) GWT java - javascript compiler : 
          The Java code for the GWT application project is compiled by the Java-to-JavaScript 
          compiler into pure HTML and JavaScript.
    2) 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.
    3) 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.
         of course free to use the entire Java class library for the server-side implementation. 
    4) 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.


    Question: What is Asynchronous server call and Synchronous server call ?
    Answer : Synchronous : Wait until server responds with the reply.
                    Asynchronous : Allow the page to continue to processed and process the reply 
                                                 from server when it is arrived.
    Question : is GWT server calls are synchronous or Asynchronous ?
    Answer Asynchronous.
    Reason : Most browser java script engines are single threaded.
    Question is AJAX server calls are synchronous or Asynchronous?
    Answer Asynchronous.
    Question: In GWT how to handle the server Response?
    Answer : by Implementing the interface "AsyncCallback" interface.
    if RPC is successful then onSuccess(Object) is called otherwise the in failure
     onFailure(Throwable) is called.
    Question :Write an Example implementation of interface AysnCallback Interface?
    Answer :
                         Shapes.getShapes(dbname,new AsyncCallback() {
                          public void onSuccess(Shapes[] result) {
                     //Process the result 
                  }
                   public void onFailure(Throwable caught) {
                   try
                      { throw caught } catch(Excpetion e) { // }
    Question: What is the latest Version of GWT ?
    Answer : Version 2.1.

    Question : Explain about GWT RPC ?
    Answer: GWT provides simple, Asynchronous RPC and Object Serialization that allows client and server to talk.GWT includes a GWT RPC package for enabling communication with server resources.
    That Package includes:
                   1) Two interfaces 
                2) Service implementation.
    Two interfaces are :
                  a) Synchronous interface.
                  b)Asynchronous Interface.


     Synchronous Interface:
            A Synchronous interface extends RemoteService interface and defines the methods
            your service exposes.
    Example  Program :
                 package com.example.Employee.client;
                 import com.google.gwt.user.client.rpc.RemoteService;
                public interface HelloService extends RemoteService {
                           String sayHello(Person p);
                }
    Asynchronous Interface:
        a) Same name as Synchronous interface, but with Async Suffix.
        b) Does not extends Remote service Interface.
        c) Should have all the methods of the synchronous interface.
        d) All methods should have return type of void.
         e)Throw no Exceptions.
         f)Additional final Reference parameter of type AsyncCallback.
    Example Program :
            package com.example.Employee.client;
            import com.google.gwt.user.client.rpc.AsyncCallback;
            public interface HelloServiceAsync {
                     void sayHello(Person p,AsyncCallback callback);
              }
    Note : Above two interfaces or in client Side.
    Service implementation :
    must create a server-side implementation of your client side synchronous RemoteService interface.
    this must extends the GWT RemoteServiceServlet class.
    Example Program : 
                 package com.example.Employee.server;
                 import com.example.Employee.client.HelloService;
                 import com.example.Employee.client.Person;
                   public class HelloServiceImpl implements HelloService {
                        public String sayHello(Person p) {
            return "Hello "+p.name+" How is the Weather at "+p.address+ " ?";
    }
    }

    Note : above total 3 parts called as .
     1) Synchronous client service interface.
     2) Asynchronous client service interface.
    3) server implementation service servlet.

    Note: And the last part in RPC is Servlet, through which the client side class communicates.It is
    an actual Implementation of RemoteServiceServlet.
    Example Program : 

    package com.example.Employee.server;
    import com.example.Employee.client.HelloService;
    import com.example.Employee.client.Person;
    import com.google.gwt.user.server.rpc.RemoteServiceServlet;

    public class HelloServlet extends RemoteServiceServlet implements HelloService {
    private HelloService impl = new HelloServiceImpl();
    public HelloServlet(){
    super();
    }
    public String sayHello(Person p) {
    //Pass through from servlet to Implementation.
    return impl.sayHello(p);
    }
    }

    Note : Actually Speaking the server side RemoteService  implementation  and RemoteServiceServlet    
              implementation,can be combined by doing like this .
    Combination program:
     RemoteService  implementation  and RemoteServiceServlet implementation

    package com.example.Employee.server;
    import com.example.Employee.client.HelloService;
    import com.example.Employee.client.Person;
    import com.google.gwt.user.server.rpc.RemoteServiceServlet;

    public class HelloServiceImpl extends RemoteServiceServlet implements HelloService {
    public String sayHello(Person p) {
    // TODO Auto-generated method stub
    return "Hello "+p.name+" How is the Weather at "+p.address+ " ?";
    }
    }


    Question : Why you want separate the RemoteService implementation and RemoteServletService
                     implementation ?
    Answer :  Because in larger projects we are like to use the RemoteService outside of remoteServlet
      Service implementation.
    Question : What is the use of Asynchronous interface?
    Answer : Service side implementation of client side synchronous interface can be accessible in the 
                   client side through the Asynchronous interface only.
    Question: How to call server from the client?
    Answer : Get the Asynchronous service interface from the static method GWT.create()
                 and bind it to relative URL for our HelloServlet.
      Example Code : 
              //Obtain Async service for interface.
               HelloServiceAsync service = (HelloServiceAsync) GWT.create(HelloService.class);
              bind it to relative URL for our HelloServlet.
              ServiceDefTarget endpoint = (ServiceDefTarget) service;
              // Bind service  to HTTP path
             endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() +"/HelloService");
    Question : What is the Job of RemoteServiceServlet?
    Answer : 1) Deserializes the object and pass it to service implementation .
                  2) Serializes the object and pass it back to service interface.
     Question : What is GWT stub ?
     Answer : 1)Sits at service interface, serializes the object pass it to RemoteServiceServlet.
                   2) Deserializes the object (result from RemoteServiceServlet) pass it to Asyncallback.
    Question : What is JSNI ?
    Answer : JSNI is required any time you want to call into native JavaScript from java , or ViceVersa.
                  There are two sides to JSNI : JAVA and JavaScript.
    Question : How to Write Javascript methods in java ?
    Answer : Using native keyword and special comments  /*-{ alert(message);}-*/.
    Question : How to access the java methods and java fields from within Javascript?
    Answer : classes with @ symbol and methods or fields names with ::
     Example :  [Optional .] @class-name:: field-name
                      [Optional .]@class-name::method-name(parm-signature)(arguments)
    Question : How to call java method from within the javascript ?
    Answer : GWT JSNI uses set of character tokens to indicate the type information for the method
                   your calling.
    Example :  A java Method a signature like this in Java.
                     public String myMethod(String[] string,int POint,boolean Flag);
                    you would invoke it from JSNI with a statement such as this.
                  x.@com.my.classname::mymethod([Ljava/lang/StringIZ)(array,2,false);
    NOTE : Mapping of Java types to JSNI type signature tokens.
                 long : J
                 int    : I
                Any Java Class :  L(fully-qualified class path); example : Ljava/lang/String;
                Arrays : [followed by the JSNI token for the contained type.

    Question : What is JavaScriptObject class?
    Answer :  It allows deep intervine between javascript and Java Objects.In otherwords we want javascript
    objects looks like java Objects. A marker that GWT uses to denote the Javascript Objects.

    Question : In Gwt how will you cancel the server request ?
       http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideRemoteProcedureCalls

    Question : In GW how will you handle the time out request?
    Answer : 


    Question: What is default time out interval for  GWT RPC call ?


    Answer RPC Services do have timeouts, its just that by default they are set to 0, which 
    effectively means no timeout.


    Good Article :
    http://blog.johnhite.com/2010/09/02/gwtgxt-and-session-timeouts/




    Question : In GWT how will you handle the Logging ?
     Answer : 


    Question : In GWT how will you display an arrayList response in a Webpage?
    Hint: There is some component in gwt.


    Question :  What is Entry Point in GWT?
     Answer : 


    Question : What are the Event Handlers in GWT ?
    Answer : See my another Post ..


    Question : what is *.gwt.xml ? what is   tag in that?
    Answer :  The  *.gwt.xml file called as XML module descriptor. The line “. tells your  
                     GWT  module to inherit the  GWT Log module.
                     Inherits uses only the fully qualified name of the GWT LOG module.


    Question : What is *.index.js file how will you add some div tags into that?
    Answer :


    Question : What are the different panels in GWT ?
    Answer : Dock-panel, vertical Panel, Flow-panel,Horizontal Panel, Absolute panel.


    Question : What is the default request time out interval for a RPC call?
    Answer   : It is zero.If you want to set the request time interval you can set using the 
                       RequestBuilder.


    Question : Will you handle the request timed out exception in server or in client side?
    Answer :


    Question : where the server side classes will diploy in GWT ?
     Answer : Diploy in websever.


    Question : Where the client side classes diploy in GWT ?
    Answer : Delpoy in GWT ..


    Question : Example of using third part GWT Module ?
    Answer :  Gwt Module name : GWT log module .


                Advantages of this mudule :
                 1)  Able to display the error,debug,info and warning messages as your app runs.
                 2) Set log level globally .
                 3) Even turnoff logging locally.



    AWS certification question

    AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...