Java Interview Questions - Servlets

 
Q. What is Servlet?
A. A servlet is a Java technology-based Web component, managed by a container called servlet container or servlet engine, that generates dynamic content and interacts with web clients via a request\/response paradigm.
Q. Why is Servlet so popular?
A. Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server.
Q. What is servlet container?
A. The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent, decodes MIME-based requests, and formats MIME-based responses. A servlet container also contains and manages servlets through their lifecycle.
Q. When a client request is sent to the servlet container, how does the container choose which servlet to invoke? (Job Interview Favourites)
A. The servlet container determines which servlet to invoke based on the configuration of its servlets, and calls it with objects representing the request and response.
Q. If a servlet is not properly initialized, what exception may be thrown?
A. During initialization or service of a request, the servlet instance can throw an UnavailableException or a ServletException.
Q. Given the request path below, which are context path, servlet path and path info?
/bookstore/education/index.html

A.
context path: /bookstore
servlet path: /education
path info: /index.html
Q. What is filter? Can filter be used as request or response?
A. A filter is a reusable piece of code that can transform the content of HTTP requests,responses, and header information.
Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.
Q. When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?
A. I know all major browsers ignore it even though the HTML 3.2 and 4.0 specifications require it. But building a DOCTYPE line tells HTML validators which version of HTML you are using so they know which specification to check your document against. These validators are valuable debugging services, helping you catch HTML syntax errors.
Q. What is new in ServletRequest interface?(Servlet 2.4)(Job Interview Favourites)
A. The following methods have been added to ServletRequest 2.4 version:
public int getRemotePort()
public java.lang.String getLocalName()
public java.lang.String getLocalAddr()
public int getLocalPort()
Q. What is JMS?
A. Java Message Service (JMS) is the new standard for interclient communication. It allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.
Q. What type messaging is provided by JMS?
A. Both synchronous and asynchronous.
Q. How may messaging models do JMS provide for and what are they?
A. JMS provides for two messaging models, publish-and-subscribe and point-to-point queuing.
Q. What is the point-to-point model in JMS?
A. A point-to-point model is based on the concept of a message queue: Senders send messages into the queue, and the receiver reads messages from this queue. In the point-to-point model, several receivers can exist, attached to the same queue. However, (Message Oriented Middleware)MOM will deliver the message only to one of them. To which depends on the MOM implementation.
Q. What is the publish-and-subscribe model in JMS?
A. A publish-subscribe model is based on the message topic concept: Publishers send messages in a topic, and all subscribers of the given topic receive these messages.

Q. What is the main parts of JMS applications?
A. The main parts of JMS applications are:

--ConnectionFactory and Destination
--Connection
--Session
--MessageProducer
--MessageConsumer
--Message

 
Disclaimer                        Feedback                      Suggestions