Friday, July 29, 2016

Everything About Servlet

Basic meaning of Servlet is Let Serv. 
It a technology to receive a user's Request and Serv back a Response.

In java Servlet is an Interface.
It contains four methods declaration.

public interface Servlet{
    void     destroy();
    ServletConfig     getServletConfig();
    java.lang.String     getServletInfo();
    void     init(ServletConfig config);
    void     service(ServletRequest req, ServletResponse res);
}


Usually developers prepare servlet classes to receive HTTP request and send back HTTP Response.
Servlet works on the HTTP (Hyper Text Transfer Protocol) protocol.

The servlet interface contains method to Inititlize a servlet, to serv the request, and to provide back response.
and to destroy or remove servlet from the server.

To use this servlet interface or to implement this servlet interface, developer can prepare a class which extends the GenericServlet (javax.servlet.GenericServlet) class OR developer can extends the
HttpServlet(javax.servlet.http.HttpServlet) class.

All the servlet classes have their servlet life cycle.
First the Servlet is Initialized by the container using the init(ServletConfig config) method.


Then all the clients requests are handled using the service(ServletRequest req, ServletResponse res) method and finally servlet is destroyed by the container.
(Note: All the Servlet instances are destroyed when server is shutting down )


The init(ServletConfig config) method is called exactly once in the life cycle of a servlet. It is called by Container.


Before serving any request the servlet's init methos's execution must be successfully complete.

All servlets have their configuration information in the ServletConfig object.
ServletConfig object are servlet specific.

Servlet is initialized on the applications startup or on the first request received to that servlet.


There is always one instance of each servlet in webapp.
Developer cannot destroy servlet on their need base. Only container can destroy the servlet.

ServletConfig (Servlet Configuration)

public interface ServletConfig{
    java.lang.String     getInitParameter(java.lang.String name);
    java.util.Enumeration<java.lang.String>     getInitParameterNames();
    ServletContext     getServletContext();
    java.lang.String     getServletName();
}

ServletConfig is an Interface


When the Web Container initializes the Servlet then it container creates the ServletConfig object by reading servlet specific information from the web.xml file and passes the ServletConfig object to the Servlet's init method.

There is always one ServletConfig object per servlet instance.
Developer can get the ServletConfig object using the getServletConfig() method.
i.e.


ServletConfig sc = getServletConfig();
out.println(sc.getInitParameter("dbUrl"));

ServletConfig object provides the ServletContext object using the getServletContext() method.
It provides the Init Parameters values configured into web.xml file, using the getInitParameter(java.lang.String name) method.
It provides the Servlet Instance name using the getServletName() method.
It provides its own Init Parameters names using the getInitParameterNames() method.

ServletContext (Servlet Context)

ServletContext is an Interface


public interface ServletContext{
    .......
    java.lang.Object     getAttribute(java.lang.String name);
    java.util.Enumeration<java.lang.String>     getAttributeNames();
    java.lang.String     getContextPath();
    java.lang.String     getInitParameter(java.lang.String name);
    .......
}


It has lots of more  methods.
There is one ServletContext object "per application" per JVM(Java Virtual Machine).


Container created the ServletContext object when it created the servlet config object.


It passed the ServletContext object to the servlet config. so developer can have the servlet context object using the ServletConfig object.


Developer can put all the application specific informtion into the servlet context object. So, the information will be accessible to whole application.


It means to share the information between multiple servlets in a web app, servlet context can be used.

Thursday, July 7, 2016

Android N Features List


Android N Features
Android N

1) Android N will allow users to open two apps in split-screen mode on Nexus devices.
i.e. This means, for example, users can keep tweeting while watching a video on YouTube.

2) Android N brings with it more Quick Settings when you slide the notifications pane down. 

3) Android N may help solve this, courtesy the new feature called 'Bundled notifications'. With this feature, users can group together notifications from each app in the menu and one will just need to tap the bundle to read individual alerts.

4) Android 7.0, Doze will work not only when your phone is not in use, but also when the screen is turned off. This is expected to improve the battery life.

5) In Android N double-tapping the Recent Apps button from homescreeen will open the last-used app, while double-tapping the button when an app is already open will take you to the app you had open just before.

6) Android N native file browser are: hamburger menus, searchability by file types and folders, the option to move and share files, and Google Drive integration. You can even have multiple instances of the file browser open at the same time.

7) Android N allows users to block phone numbers at the system level, directly from apps like Dialler, Hangouts or Messenger.

8) Android N provides the ability to add your medical information on the lockscreen itself in case of an emergency. You can go to Users in Settings and select the Emergency Information option; fill the details you want to reveal and add an emergency contact for good measure.

9) Android N brings a few changes that can be found in the Settings app under different menus. These include a new night theme, data saver that blocks background data consumption, and provision for display calibration as well as screen zooming, among others.

Wednesday, July 6, 2016

What is HashTable initial capacity and load factor ?

HashTable instance has two main parameters which affect it performance.
Initial Capacity and the Load Factor. 
Initial Capacity is the capacity of the hashtable instance when it is created. 
Load Factor is used to measure how full the hashtable instance is allowed to be before its initial capacity is automatically increased. when the number of entries into the hashtable is exceeds the product of current capacity and load factor, the hashtable is rehashed. It means its internal data structures are rebuild. so that the has table has new free number of buckets. 

Java List Interview Questions Answers

When the contains() method of list throws NullPointerException ?
Ans : if the specified element is null and this list does not permit null elements.

Is it safe to modify the array of object returned by the toArray() method of list ?
Ans : The returned array will be "safe" in that no references to it are maintained by this list.  (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.

Explain Remove method of list
Ans: Removes the first occurrence of the specified element from this list,  if it is present (optional operation).  If this list does not contain the element, it is unchanged.  More formally, removes the element with the lowest index  if this list contained the specified element (or equivalently, if this list changed  as a result of the call).
     
This method throws ClassCastException if the type of the specified element is incompatible with this list (optional)

This method throws NullPointerException if the specified element is null and this list does not permit null elements
This method throws UnsupportedOperationException if the operation   is not supported by this list

Is it possible to get some number of elements sequence from the List ?
Ans: Yes it is possible using the ListIterator<E> listIterator(int index) method.
This method will return all the elements from the list from the specified index position to the size of the list. 

Also you can get some specifi range of elements from list using the 
List<E> subList(int fromIndex, int toIndex) method. here the elements at the fromIdex will be inclusive and toIndex is exclusive. If both of the specified index values are same then the returned list will be empty.
And any non structural changes made into the returned list will be reflected into the original list. (Structural modifications are those that changes the size of the this list)

How can you remove five elements in one shot from the list without using the remove(int index) method ?
Ans: using the subList(int fromIndex, int toIndex) method you can remove multiple elements simultaneously from 'this' list. 
exmple : subList(4,6).clear();
Here the 4th and 5th element will be removed from the list.





Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...