KEMBAR78
Servlet Interview Question: Q: Life Cycle of Servlet? | PDF | Java Servlet | Constructor (Object Oriented Programming)
0% found this document useful (0 votes)
115 views4 pages

Servlet Interview Question: Q: Life Cycle of Servlet?

The document contains questions and answers related to servlets. It discusses the servlet lifecycle including initialization, service, and destruction methods. It compares doGet and doPost methods, and servletContext versus servletConfig. Other topics covered include preinitialization, communicating between servlets, using filters, and functions of the servlet container such as lifecycle management and multithreading support.

Uploaded by

Syed Jabeer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views4 pages

Servlet Interview Question: Q: Life Cycle of Servlet?

The document contains questions and answers related to servlets. It discusses the servlet lifecycle including initialization, service, and destruction methods. It compares doGet and doPost methods, and servletContext versus servletConfig. Other topics covered include preinitialization, communicating between servlets, using filters, and functions of the servlet container such as lifecycle management and multithreading support.

Uploaded by

Syed Jabeer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Servlet Interview Question

Contents Q: Life cycle of Servlet? Q: What is preinitialization of servlet? And which Tag is used for this? Q: Difference between do et and do!ost"#? Q: Difference between servlet$onte%t and Servlet$onfig? Q: Does servlet has constructor? $an we provide e%plicit constructor? What is the use of init"#? Why there are overloaded version of init &ethod? Q: $an we call destroy &ethod fro& service? Q: 'ow to co&&unicate between ( servlet? Q: Why init is used and not constructor? $an we use constructor instead of init? Q: Difference between Servlet and Applet? Q: What is the difference between callling a )e*uestDispatcher using Servlet)e*uest and Servlet$onte%t? Q: 'TT!Servlet)e*uest and 'TT!Servlet)esponse both are interface then who provide i&pli&entation for these (? Q: What is filter how it is different fro& Servlet? Q: $an we invo+e ,S! error page fro& servlet? Q: Latest -ersion of Servlet? Q: Advantage of Servlet over $ .? "/resher only# Q: What servlets destroy &ethods get called? Q: Difference between genericServlet and 'TT!Servlet? Q: Why is 'ttpServlet declared abstract? Q: 0se of Servlet wrapper classes? Q: What is deploy&ent descriptior? Q: 'ow can we invalidate e%isting session? Q: What is servlet lazy loading? Q: 'ow are filters? Q: What are the functions of the Servlet container?

Q: Life cycle of Servlet?


A: Container control the life cycle of servlet in which it is deployed. Steps : 1- Container first check if an instance of the servlet exist or not if it doesn't find any servlet, Web container Loads the servlet class or else o to step ! "- Creates an instance of the servlet class. #- $nitiali%es the servlet instance by callin the init&' (ethod&Servlet Life cycle (ethod'. )ow servlet is ready to serve the re*+est. When ever a re*+est co(es in for this servlet !- Container invokes the service&' (ethod, passin a re*+est and response ob,ect. )ote: Servlet will handle all re*+est in Service (ethod. - - When servlet container deter(ines that the servlet sho+ld be re(oved fro( the service, it calls the destroy&' (ethod of the servlet to allow servlet to release any reso+rces it is +sin . .he followin are the life cycle (ethods of a servlet 1- init&' "- service&' #- destroy&'

Q: What is preinitialization of servlet? And which Tag is used for this?


A: Check above for the life cycle steps of servlet. /ere initiali%ation&init (ethod called' happens only when the first re*+est for servlet co(es to container, this is called la%y loadin . So(e ti(e it is re*+ired to load adn initiali%e the servlet when container starts. .his is called pre initiali%ation. $t can be achieved via ta 0

Q: Difference between doGet and doPost()?


A: do1et (ethod will be invoked with re*+est is of type 12. and do3ost (ethod will be invoked when re*+est is of type 34S.. there are other type of re*+est available like p+t delete..

Q: Difference between servletContext and ServletConfig?


A:

Q: Does servlet has constructor? Can we provide explicit constructor? What is the use of init()? Why there are overloaded version of init method?
A:

Q: Can we call destroy method from service?


A:

Q: How to communicate between 2 servlet?


A:

Q: Why init is used and not constructor? Can we use constructor instead of init?
A:

Q: Difference between Servlet and Applet? Q: What is the difference between callling a RequestDispatcher using ServletRequest and ServletContext? Q: HTTPServletRequest and HTTPServletResponse both are interface then who provide implimentation for these 2? Q: What is filter how it is different from Servlet? Q: Can we invoke JSP error page from servlet? Q: Latest Version of Servlet? Q: Advantage of Servlet over CGI? (Fresher only) Q: What servlets destroy methods get called?
A: Server sh+ts down. 5d(inistrator (an+ally +nloads. &/ow can we (an+ally do this6' is there any other way6

Q: Difference between genericServlet and HTTPServlet? Q: Why is HttpServlet declared abstract? Q: Use of Servlet wrapper classes? Q: What is deployment descriptior? Q: How can we invalidate existing session?
A:

Q: What is servlet lazy loading?


A: Container doesnot initiali%e the servlets ass soon as it starts +p, it initiali%es a servlet when it receives a re*+est for that servlet first ti(e. .his is called la%y loadin . .he servlet specification defines the ele(ent, which can be specified in the deploy(ent descriptor to

(ake the servlet container load and initiali%e the servlet as soon as it starts +p. .he process of loadin a servlet before any re*+est co(es in is called preloadin or preinitiali%in a servlet.

Q: How are filters?


A: 7ilters are 8ava co(ponents that are +sed to intercept an inco(in re*+est to a Web reso+rce and a response sent back fro( the reso+rce. $t is +sed to abstract any +sef+l infor(ation contained in the re*+est or response. So(e of the i(portant f+nctions perfor(ed by filters are as follows: Sec+rity checks 9odifyin the re*+est or response :ata co(pression Lo in and a+ditin ;esponse co(pression 7ilters are confi +red in the deploy(ent descriptor of a Web application. /ence, a +ser is not re*+ired to reco(pile anythin to chan e the inp+t or o+tp+t of the Web application.

Q: What are the functions of the Servlet container?


A: .he f+nctions of the Servlet container are as follows: Lifecycle (ana e(ent Co((+nication s+pport 9+ltithreadin s+pport :eclarative sec+rity 8S3 s+pport

You might also like