Basic Java servlet interview questions

  1. What is the difference between CGI and Servlet?
  2. What is meant by a servlet?
  3. What are the types of servlets? What is the difference between 2 types of Servlets?
  4. What is the type of method for sending request from HTTP server ?
  5. What are the exceptions thrown by Servlets? Why?
  6. What is the life cycle of a servlet?
  7. What is meant by cookies? Why is Cookie used?
  8. What is HTTP Session?
  9. What is the difference between GET and POST methods?
  10. How can you run a Servlet Program?
  11. What is the middleware? What is the functionality of Webserver?
  12. What webserver is used for running the Servlets?
  13. How do you invoke a Servelt? What is the difference in between doPost and doGet methods?
  14. What is the difference in between the HTTPServlet and Generic Servlet? Explain their methods? Tell me their parameter names also?
  15. What are session variable in Servlets?
  16. What is meant by Session? Tell me something about HTTPSession Class?
  17. What is Session Tracking?
  18. Difference between doGet and doPost?
  19. What are the methods in HttpServlet?
  20. What are the types of SessionTracking? Why do you use Session Tracking in HttpServlet?
This entry was posted in Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

16 Comments on Basic Java servlet interview questions

  1. Ken Hutchinson
    Posted 11/30/2004 at 3:14 am | Permalink

    It would be great if answers were provided. Not the out of the book response, but real comments about how choices affect production by choosing one option over another. What are the best practices assoc. with each of these topics?

  2. srikanth
    Posted 7/28/2007 at 5:46 am | Permalink

    1 Q,..
    Answer..
    Advantegs of servlets over CGI are
    1..servlets are multithreaded which can support multiple users requests ..
    that is servlet is a resource and where as requests are treated as threads .so multiple requests (threads) can acess a single instance of servlet resource asynchronously ..where as CGI provide a new instance for every request it is a single thread model .By creating new instance every request server wont supprot multiple requests
    2..servlets are used to generate dynamic content
    3.. servlets are platform independent
    4..servlets are more efficient compare to other server side programming

    This answer is according to me ..you can find more on internet

  3. srikanth
    Posted 7/28/2007 at 5:50 am | Permalink

    2Q,.
    Answer
    Servlet is a server side component written in java ,which can host request of client , process the request and response sent back to the client

  4. srikanth
    Posted 7/28/2007 at 5:55 am | Permalink

    3Q,.
    Answer
    There are two types of servlets provided by servlet API those are
    GenericServlet ..It can use for any type of protocols(http,ftp,telnet)
    it is protocol independent ,it support service() method only
    HttpServlet..It can use for only http protocol ,it support doGet() and doPost() methods with Service() methods

  5. srikanth
    Posted 7/28/2007 at 5:58 am | Permalink

    4Q.,
    Answer .
    Http server request can sent in two types one is GET and second one is POST

    sample code

    it is used by html

  6. surulikrishna
    Posted 8/14/2007 at 1:21 am | Permalink

    Q.19.What are the methods in HttpServlet?

    doGet()
    doPost()
    doHead()
    doPut()
    doOptions()
    doDelete()
    doTrace().
    Both these classes are abstract.

  7. surulikrishna
    Posted 8/14/2007 at 1:29 am | Permalink

    Q.9.What is the difference between GET and POST methods?
    Using GET method,We can able to pass 2K data from HTML.
    In POST method,We does not have any size limitation.

  8. surulikrishna
    Posted 8/14/2007 at 2:15 am | Permalink

    Q.20.What are the types of SessionTracking?

    1.Using Cookies
    2.Using URL rewriting
    3.Using HTTP session
    4.Using Hidden form fields.

  9. ashraf
    Posted 10/30/2007 at 12:17 am | Permalink

    RE: What is the difference between Service, doGET, doP…
    ——————————————————————————–

    when we make a request to any servlet, request doesn’t goes directly to the servlet instead it will go to the service method of the super class and then it was passed as a parameters to the service method of ur class.In doGet() method the data will append to the url as a querrystring and we can’t send huge amount of data using doGET() method. Where as in doPost()method the data can be directly sent to browser without displaying it in the url.withis we can send as much of data as we can.But doGet() method is little faster when compared to doPOst().but it is not recommended as for some sensitive messages like password will be displayed as a querrystring in it.

  10. sai
    Posted 12/3/2007 at 3:35 pm | Permalink

    Servlet is a java program that is run inside a servlet engine called web server.It take requests from client and responds to those requests.

  11. sai
    Posted 12/3/2007 at 3:40 pm | Permalink

    Life cycle of sevlet includes

    init()–used for initialization
    service()–for processing client requests
    destroy()– used for closing

  12. sai
    Posted 12/3/2007 at 3:49 pm | Permalink

    difference between GET and POST methods

    when method is GET browser appends request data as query string and is sent to server i.e request data is appended to URL, as the data is appended to URL secure information like passwords can be viewed by others which is displayed on address bar.As data is appended to URL large amounts of data cannot be sent to server

    when methos is POST request information is sent to server as part of the body request so large amounts of data can be sent to server securely.

  13. sai
    Posted 12/3/2007 at 3:54 pm | Permalink

    5Q. what are the exceptions thrown by servlet
    A. Exceptions thrown by servlet are:
    ServletException
    IOException

  14. Posted 10/11/2008 at 10:21 am | Permalink

    ANS-9 ) the get method is simple to handle it sends the data to server by adding data to URL of browser. so it has disadvantage that if your servlet is sending password that will be visible on browser… and there is restriction on the size of data that can be send by get Method..

    but ib post methos the data gets ecoded in HTTP-streams and then send to server… so it has security features and size of the data that can be send is much more that in get menhod..

    bye :- ajay

  15. Posted 10/11/2008 at 10:25 am | Permalink

    ans-17) session tracking means suppose if your site provide a login facility and it is accessed by many user at a time than you need a way to know request is coming from which user… so session tracking is needed we uses many methos for it like hidden fields,url rewriting , or APIS can be user.

    URL rewriting is used when your site provides the facility of ANONYMOUS LOGIN

    bye :- it’s ajay

  16. Sekhar Badugu
    Posted 12/16/2009 at 8:59 am | Permalink

    What is meant by cookies? Why is Cookie used?

    Ans: cookies are used to maintain small amount of data at client side.What

    webserver is used for running the Servlets?

    Ans: Mostly tomcat can be used to run the servlets and servlet will have presentation and business logic.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*