Tuesday, October 13, 2015

EJB Interview Questions and Answers

1. What is EJB?
Enterprise Java Beans are the server side components that run inside the EJB container and encapsulates the business logic of an enterprise application.
2. What is a J2EE container?
Containers are the interface between a component and the low level platform specific functionality that supports the component. The application server maintains control and provides services through an interface or framework known as a container.
3. What are the types of J2EE container types according to J2EE specification?
There are five defined J2EE container types (three server side and two client side). Three server side containers are as follows:
  • The server itself, which provides the J2EE runtime environment.
  • An EJB container to manage EJB components.
  • A web container to manage servlets and java server pages.
Two client side containers are as follows:
  • An application container for standalone GUIs, console, and batch type programs.
  • An applet container, meaning a browser, usually with the java plug-in.
4. what is a J2EE component and what are its types?
It is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. There are three types of components: 
  • Client components, which correlate to the client containers. 
  • Web components - Servlets and JSPs. 
  • EJB components - are business components that run on the server, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance.

Monday, October 12, 2015

Servlet Interview Questions and Answers

6. Explain MVC design pattern?
Model-View-Controller (MVC) is a design pattern which divides a software application into three parts namely model, view and controller.
  • A model deals with behavior of the application. It contains the data and business logic of the application. It notifies views and controllers when there is change in its state.
  • A view renders the information to the user so that it looks attractive and appealing. It takes information from the model using which it generates output.
A controller takes input from user and sends command to model or view. It controls the flow of application.
7. Explain the web application directory structure?
web application’s directory structure has document root which contains JSP files, HTML files, JavaScript files and static files such as image files. There is a directory WEB-INF under the document root which contains configuration files related to application. This configuration files can’t be served directly to the client. The WEB-INF directory contains:
  • /WEB-INF/classes/* : It contains compiled class files
  • /WEB-INF/lib/*.jar : It contains different library jar files
  • /WEB-INF/web.xml : It is a deployment descriptor that specify the web application configuration.
8. what are the two packages that deal with servlets?
Servlet API exist in two packages:
  • Javax.servlet: The classes and interfaces in javax.servlet are not protocol dependent. e.g. It can support different protocols like HTTP, FTP.
  • Javax.servlet.http: The classes and interface in this package are specific for requests using HTTP protocol. Some of the classes and interfaces in this package extend those of javax.servlet package.
9. Explain servlet class hierarchy?
  • Interface Servlet: It declares the standaed API’s which all the servlet implementations needs to define. All servlet classes must implement this interface directly or indirectly.
  • Class GenericServlet: It defines a generic, protocol independent servlet. Servlet developed to cater NON-HTTP requests.
  • Class HTTPServlet: Servlet used to cater client HTTP requests.
10. What is Servlet interface?
The Servlet interface is the abstraction of Java Servlet API. It declares the life cycle methods of a servlet. All the servlet classes must implement it either directly or indirectly by extending a class which implements the Servlet interface. E.g. HTTPServlet, GenericServlet.

Sunday, October 11, 2015

Servlet Interview Questions and Answers

1. What is a servlet?
A servlet is a java program that runs within a web server and serves the client request hence the name servlet. Servlets can receive and respond to requests from web clients working on any client-server protocol, but HTTP is predominantly used. Servlet is a server side script technology which can process client request and give back the response.
2. What is a servlet container?
A servlet container is a container for servlets which is responsible for managing the servlets. The main functions are load, initialize and execute servlets to serve client requests. When a request is received, the container decides what servlet to call based on a configuration file. Servlet container comes installed with the web servers. Examples: Tomcat, Glassfish, JBoss.
3. What is CGI?
Common Gateway Interface(CGI) was the most commonly used for server side scripting before the evolution of the java servlet technology. With traditional CGI, a new process is started for each HTTP request eating up more of the CPU cycles thus degrading the performance of the system.
4. What are the advantages of servlet over CGI?
  • When a CGI script is called, a new process is created for each and every client request. But for servlets, each request is handled by a separate thread. Hence, servlet is more efficient because process creation takes more time compared to thread creation.
  • For each new CGI requests, CGI script is copied into memory. But with servlets, there is only one copy across requests and is shared among threads.
  • In CGI multiple process serves concurrent requests. But for servlets, only single instance serves concurrent requests.