R4R
Right Place For Right Person TM
 
R4R Java Core Java Faqs
Previous

Home

Next

 


Java Servlet Interview Questions and Answers

Q1:What is the servlet?
Ans:
Servlet is a server side programming language Which takes request in form of Http and gives response in the form of Http.

Q2:What is the architechture of servlet package?
Ans:
Servlet Interface is the central abstraction. All servlets implements this Servlet Interface either direclty or indirectly ( may implement or extend Servlet Interfaces sub classes or sub interfaces)

Servlet
|
Generic Servlet
|
HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests
|
MyServlet



Q3:What is the difference between HttpServlet and GenericServlet?
Ans:
A GenericServlet has a service() method to handle requests.HttpServlet extends GenericServlet added new methods
doGet()
doPost()
doHead()
doPut()
doOptions()
doDelete()
doTrace() methods
Both these classes are abstract.

Q4:What's the difference between servlets and applets?
Ans:
Servlets executes on Servers. Applets executes on browser. Unlike applets, however, servlets have no graphical user interface.

Q5:What are the uses of Servlets?
Ans:
A servlet can handle multiple requests concurrently, and can synchronize requests. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers.

Q6:When doGET() method will going to execute?
Ans:
When we specified method='GET' in HTML
Example : < form name='SSS' method='GET'>

Q7:When doPOST() method will going to execute?
Ans:
When we specified method='POST' in HTML
< form name='SSS' method='POST' >

Q8:What is the difference between Difference between doGet() and doPost()?
Ans:GET Method
 Using get method we can able to pass 2K data from HTML
All data we are passing to Server will be displayed in URL (request string).This is used to sent small size data.
POST Method: In this method we does not have any size limitation. All data passed to server will be hidden, User cannot able to see this info on the browser. .The data is send into a small packets. This used to sent large amount of data.

Q9:What is the servlet life cycle?
Ans:
When first request came in for the servlet , Server will invoke init() method of the servlet. There after if any user request the servlet program, Server will directly executes the service() method. When Server want to remove the servlet from pool, then it will execute the destroy() method. The init() and destroy() methods are called at only one time. But service() method can call at each request. The service() method creates a separate thread for each request and gives response according to request.

Q10:Which code line must be set before any of the lines that use the PrintWriter?
Ans:setContentType()
method must be set.


Previous

Home

Next

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R