REGISTER FREE to Receive Instant Job

Sunday, 7 December 2014

Servlet interview questions

1- Servlet

  • Servlet is a technology for developing Web Applications in Java. Apart from technology, Servlet term is also used to describe those programs which are developed using this technology.
  • As an Application Component, Servlet represents such programs which are executed within a Web Server and generates dynamic html. Before Servlets, Dynamic Web Applications used to be developed using CGI.


2- How many objects of a servlet is created?
Only one object at the time of first request by servlet or web container.

3-What is the life-cycle of a servlet?
  • Servlet is loaded
  • servlet is instantiated
  • servlet is initialized
  • service the request
  • servlet is destroyed

4-Difference between attributes and parameters.

  • Parameters represents data received as part of request whereas attributes represents data that is stored by servlet in ServletRequest object for another servlet involved in processing the same request.
  • Parameter represents String data whereas Attribute represents object data.
  • Parameters can only be read by a servlet whereas attributes can be read, set, removed & replaced by the Servlets.

5-Who is responsible to create the object of servlet?
The web container or servlet container.

6-What is difference between PrintWriter and ServletOutputStream?

  • PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class. The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.
7-What is Session Tracking?
Session simply means a particular interval of time. Session Tracking is a way to maintain state of an user.Http protocol is a stateless protocol.Each time user requests to the server, server treats the request as the new request.So we need to maintain the state of an user to recognize to particular user.

8-Cookies
A cookie represents textual information (in the form of key/value pair) that is sent by the server as part of response to the client machine so that it can be sent by the client to the server with subsequent request.

9-What is load-on-startup in servlet?
The load-on-startup element of servlet in web.xml is used to load the servlet at the time of deploying the project or server start. So it saves time for the response of first request.

10-Which event is fired at the time of project deployment and undeployment?
ServletContextEvent.

11-Which event is fired at the time of session creation and destroy?

HttpSessionEvent.

2 comments:

  1. The servlet interview questions shared were very much useful The detailed descriptions of the answer helped me answer well in the interview my sincere thanks for sharing this valuable post
    java training in chennai

    ReplyDelete

Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.