Wednesday 25 April 2012

Java/Servlets interview questions: -Can you explain the concept of SSI(Server Side Includes)?

Server Side Includes (SSI) are commands and directives placed in Web pages that are evaluated by the Web server when the Web page is being served. SSI are not supported by all web servers. So before using SSI read the web server documentation for the support. SSI is useful when you want a small part of the page to be dynamically generated rather than loading the whole page again.

Below is the code for SSI which needs to be inserted in between the HTML tags.

Here the CODE attribute specifies the servlet name. The CODEBASE attribute indicates the servlet location. If you are using a servlet deployed in the same Web server, you can omit the CODEBASE attribute. You can pass any request parameters to the servlet using the PARAM tags.

Below is the code how the SSI looks in the HTML.

See the following video on Java which describes EJB(Enterprise Java Beans): -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Friday 20 April 2012

Java/Servlets interview questions: -Mention differences between getSession(true) and getSession(false)?

Session's can be considered as a series of related interactions between client and the server that take place over a period of time. Because HTTP is a stateless protocol these series of interactions are difficult to track. That’s where we can use HttpSession object to save in between of these interactions so that server can co-relate between interactions between clients.

Figure: - Session code walkthrough

Above is the code snippet which displays session data. Step1 returns an HttpSession object from the request object. “true” parameter in the “getsession” function ensures that we get a session object if there is no current session object in request which ensures that we never get a null session object. In Step 2 we are using the “getattribute” function to return the session value. In step 3 we are setting the session value with “Name” key.

See the following video on Java which describes Hibernate and it concepts: -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Monday 16 April 2012

Java interview questions: - Can you explain cookies in Java?

Cookies are piece of data which are stored at the client’s browser to track information regarding the user usage and habits. Servlets sends cookies to the browser client using the HTTP response headers. When client gets the cookie information it’s stored by the browser in the client’s hard disk. Similarly client returns the cookie information using the HTTP request headers.
Figure: - Cookies in action

Figure: - Cookies code walkthrough
Above is a simple snippet which shows how to use cookies. To create a cookie you need to use the “Cookie” class. In the above snippet step1 creates a cookie using the “Cookie” class. In this case “favoritecookiebook” is the name of the cookie. In Step 2 you can see how a cookie has been added to the response. Step 3 code shows how to get all the cookies which has come in the current request header. Step 4 shows the way to get a cookie from a collection in this case we wanted to retrieve “favoritecookiebook” from the cookies collection.

See the following video on Java which describes Batch processing in Hibernate: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Friday 13 April 2012

Java interview questions: - Which other protocol is also called as stateless protocol?

A protocol is stateless if it can remember difference between one client request and the other. HTTP is a stateless protocol because each request is executed independently without any knowledge of the requests that came before it.


Figure: - HTTP Protocol in action

Above is a pictorial presentation of how a stateless protocol operates. User first sends “request1” and server responds with “response1”. When the same user comes back with “request2” server treats this as new user and has no idea that it’s the same user who has come with the request. In short every request is a new request for the HTTP protocol so it’s called as a stateless protocol.

See the following video on java for implementation of many To One relations in database using Hibernate: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Monday 2 April 2012

Java/servlets interview questions: - How will you explain Servlets and its lifecycle?

Servlets are small program which execute on the web server. They run under web server environment exploiting the functionalities of the web server.

Servlet life cycle
Figure: - Servlet Life cycle

There are three methods which are very important in servlet life cycle i.e. "init”, "service" and "destroy". Server invokes "init ()" method when servlet is first loaded in to the web server memory. Servlet reads HTTP data provided in HTTP request in the "service ()" method. Once initialized servlet remains in memory to process subsequent request. So for every HTTP request "service ()" method of the servlet is called. Finally when server unloads the "servlet ()" from the memory it calls the "destroy" method which can be used to clean up any resource the servlet is consuming.

See the following video on Java/J2EE Interview question which describes String Literal Pool: -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions