Top Servlet Questions Part1 - Tech Interview Club

Latest

interview questions for java,spring,servlet,jsp,hibernate,webservices,.net,html,javascript,andriod,jquery

Comments

Saturday, 24 June 2017

Top Servlet Questions Part1


1.What is Servlet?

  Servlet is java based technology.it is used to create web applications.it is server side platform independent, dynamic, multithreaded java program. Servlet is a web component that is deployed on the server to create dynamic web page.It is extend the capabilities of the servers and respond to the incoming request. It can respond to any type of requests. When multiple users make request to the same servlet then all request will be processed by servlet container by creating the multiple threads for same servlet.
We want to develop a servlet we must import javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet API.
The javax.servlet package contains many interfaces and classes that are used by the servlet or web container. These are not specific to any protocol.
The javax.servlet.http package contains interfaces and classes that are responsible for http requests only.
The HttpServlet class provides methods, such as doGet() and doPost(), for handling HTTP-specific services.
Most of the times, web applications are accessed using HTTP protocol and that’s why we mostly extend HttpServlet class.
Here javax. Servlet package contains servlet interface it is pre defined top most interface it containing life cycle methods of servlet.
2.What is Web Application?

Web application is a collection of web resource programs which can generate web pages. There are two types of web resource programs
A static web resource program generates static web pages like html, images.
A dynamic web resource program generates dynamic web pages like servlets, jsp, php, .net. These are executed dynamically by container when the client requested.
Static web pages containing fixed content forever. Dynamic web pages content changed based on input values of the request.
Web resource programs like images, JavaScript files can not generate web pages directly but they are run with support of other resource programs to generate web pages.

3. What is Request and Response model?

Client is requesting something from server. Server is basically machine that serves the client request and sends result as response to the client

4. What is What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.
5.What is Server Side Includes (SSI)?
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.

6. What is difference between the CGI and Servlet?
Ø  CGI is a specification to develop server side web resource program. Here Perl programming language will be used to develop the web resource programs based on CGI specifications.
Ø  CGI is process based server side technology.so it started new process for every new client request. If no of requests are increased then no of process also increased so it decreases the performance of web application. Because process is heavy weighted they take more memory and time for processing and also take a lot of time for control switching or context switching.
Ø  Control Switching: the procedure of transforming the control from one process to anther process and one thread to anther thread is called schedule based control switching or context switching.
Ø  So the CGI based web application became non scalable applications.
Ø  Scalable: if an application is giving same performance irrespective of increasing or decreasing of no of requests is called scalability.
Ø  CGI uses the platform dependent languages like C, Perl and C++.
Ø  Servlet is single instance multithread based java program that means for example request is given to single servlet program then servlet container creates only one instance or object for that servlet but it creates one thread per one request basis that means 100 request are given to single servlet it creates only one object but it creates 100 threads for each requests.so it gives better performance because it creates thread not a process. So control switch time is less and thread is light weight and thread based server side application is scalable application.
Ø  Servlet is robust, scalable, portable and secure program.
Ø  There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data.
Ø  Servlets are robust because container takes care of life cycle of servlet and we don’t need to worry about memory leaks, security, garbage collection etc.
Ø  In servlet Managing of deployment descriptor web.xml file easily.





No comments:

Post a Comment