Thursday, November 25, 2010

My Interview Questions

Question : What are the new features in Java 1.6 ?
Answer :
a) Collections framework enhancements.
  1. Added new interfaces .
   a)deque : double ended queue.
   b)NavigableSet : a sorted set may be accessed or traversed either ascending or descending order.
   c)NavigableMap : a sorted map may be accessed or traversed either ascending or descending order.
 2. Added New Concrete classes :
     a) ArrayDeque - efficient resizable-array implementation of the Deque interface.
    b) AbstractMap.SimpleEntry - simple mutable implementation of Map.Entry
3.  Added methods to Arrays class:
    a) The Arrays utility class now has methods copyOf and copyOfRange that can 
       efficiently resize, truncate, or copy subarrays for arrays of all types.
Example Before:
int[] newArray = new int[newLength];
System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
After:int[] newArray = Arrays.copyOf(a, newLength);
b) Java Web Start and Java Plug-in Common Enhancements
c) Internationalization Support.
Internationalization is the process of designing an application so that it can be adapted
 to various languages and regions without engineering changes.
d)Enhancements in Java I/O.
  i) New Class console :
   The method System.console() returns the unique console associated with the
   Java Virtual Machine.
ii)  New Methods added to Class File :
   a) Methods: getTotalSpace, getFreeSpace, getUsableSpace.
Read this link :
Question : What's new in the java 1.5 ?
Answer : 1) Annonations
              2) Generics
              3) New Syntax "for" loop.
              4) Variable number of arguments.
              5) AutoBoxing.
              6) Static Import
             7) Type Safe enum
             8) Concurrent locks
             9) RMIC not Required
            10) Thread pool Executer
            11) Count Down latch
            12) Cyclic Barrier
            13)Blocking.
Question : How many objects will get create in the below scenario ?


Ans : 2 Objects...


                   1)      String a = "abc";
                   2)      String b = new String("abc");
Explanation : For the statement [ String a = "abc" ] it creates one Object in the String
 Constant Pool.For the Second Statement [ String b = new String("abc") ] it Creates
 another object in the heap memory , and placed it in the string constant pool , and 
 finally reference is added to the variable 'b'.


Note The creation of two strings with the same sequence of letters without the use
of the new keyword will create pointers to the same String in the Java String literal pool.
and creates only one object.


The String literal pool is a way Java conserves resources.

Some Important points about string literals:
  • Equivalent String Literals (even those stored in separate classes in separate packs)
  •  will refer to the same String object.
  • In general, String Literals are not eligible for garbage collection. Ever.
  • Strings created at run-time(with new Operator) will always be distinct from those created from String Literals.
  • You can reuse String Literals with run-time Strings by utilizing the intern() method.
  • The best way to check for String equality is to use the equals() method.
This is the Wonderful link :

Question : Is Serializable is marker interface?
Answer : Yes..
Question : Explain how abstraction and encapsulation achieved in Java?

 Abstraction :  suppose say List interface is an Abstraction , it do what it promises to do,
  but hide all the details of the implementation .
   In other sense we can say  it deals with the outside view of an object (interface). 
definition of abstraction is about ignoring the things that don't matter so you can 
focus on the things that do matter.    

Encapsulation :Encapsulation actually means putting data and operations on that data
 together (for example in a class).


"Information/Data hiding is accomplished in java by using Modifiers -
 By keeping the instance variables private or protected." 


Question : How to achieve Encapsulation in java ?
Ans : Define a class with all the data members declared as private so that they are
 not publically accessible to any other class and all the methods that works upon
(or) uses these data members as public. In this way encapsulation is achieved in Java.


Observation : A real world example of Abstraction and Encapsulation ?
Answer :  Very very Good Article :
  http://www.javahelpline.com/2009/06/abstraction-and-encapsulation.html
An Abstraction is a perspective and Encapsulation is an implementation to achieve
that perspective.

Define Perspective  : Appearance of things


 Question What is MVP Pattern ?
Model : Model is an interface defining the data to be displayed 
View: Interface displays the data and en routes the events to the presenter.
Presenter : It Retrieves data from the model,persists it and formats it for 
                   display in the view.


Simply,...
 Model : stores the data.
View : Represents the data.
Presenter :  Co-ordinates the Application.


Question : What is MVC Pattern ?
Though MVC comes in different flavors, control flow is generally as follows:

The user interacts with the user interface in some way. (for example,
 presses a mouse button).

The controller handles the input event from the user interface, often via
 a registered handler or callback and converts the event into appropriate
 user action, understandable for the model.

The controller notifies the model of the user action, possibly resulting 
in a change in the model's state. (For example, the controller updates
 the user's shopping cart.)

A view queries the model in order to generate an appropriate user
 interface (for example, the view lists the shopping cart's contents). 

The view gets its own data from the model. In some implementations, 
the controller may issue a general instruction to the view to render itself.

 In others, the view is automatically notified by the model of changes in
 state (Observer) which require a screen update.

The user interface waits for further user interactions, which restarts 
the cycle.

Question : What is the difference between the MVC and MVP ?
Answer
 In MVP: instead of controller we have Presenter.
In MVP: presenter have an capability of interpret the user events and 
perform any sort of logic necessary to map them to commands to manipulate
the model in the intended order.

Additionally the View in the MVP is responsible to hand over the user events 
to the Presenter,. which is the Job of Controller in MVC pattern.
And the Model in the MVP is strictly a domain Model in MVP.


image
              source from the blog : http://blog.vuscode.com
              Question : What are the differences between thread and process in Java?
              Answer:   1)   Process is separate one and thread is a part of the process.
                             2)  Thread is light weight process, where process is heavy weight.
                             3)  Threads can communicate between threads directly , where
                                  Processes must use IPC to  Communicate with other threads.
                             4) Threads share the address space of the process, where Processes having 
                                 their own address space.
                             5) Process is program in execution, where thread is separate path of 
                                execution in a program.

              No comments:

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