Post your need

J2EE Interview Questions

  • What is J2EE, and why do we need it?
    J2EE stands for Java 2 Enterprise Edition. It is a platform that provides a set of services, APIs, and protocols for developing and deploying multi-tier, web-based enterprise applications. J2EE simplifies the development process by providing a standard and reusable way of handling common tasks such as security, transaction management, scalability, and interoperability. J2EE also supports various technologies and frameworks, such as servlets, JSP, EJB, JMS, JNDI, JDBC, JAX-RPC, etc., that enable the creation of dynamic, distributed, and portable applications.
    What are the main components of J2EE?

    J2EE consists of four main components:


    J2EE application server: This software provides the runtime environment and services for executing J2EE applications. It also manages the components' resources, security, transactions, and communication.

    J2EE application: It is software that consists of one or more modules that contain the application's business logic and presentation logic. It can be deployed on one or more J2EE application servers.

    J2EE client: It is software that interacts with the J2EE application. It can be a web browser, an application client, a Java Web Start client, or a wireless client.

    J2EE services: These APIs and protocols provide the functionality and communication for the J2EE components. They include the Java Servlet API, the JavaServer Pages API, the Enterprise JavaBeans API, the Java Message Service API, the Java Naming and Directory Interface API, the Java Database Connectivity API, the Java API for XML-based RPC, etc.

    What are the types of J2EE modules?

    J2EE defines four types of modules:


    Web module: It contains the web components, such as servlets and JSPs that handle the application's presentation logic and user interaction. It also includes the web deployment descriptor, which defines the configuration and behavior of the web components. It is packaged as a WAR (Web Archive) file with a .war extension.

    EJB module: It contains the enterprise beans, which are the server-side components that handle the application's business logic and data access. It also includes the EJB deployment descriptor, which defines the configuration and behavior of the enterprise beans. It is packaged as a JAR (Java Archive) file with a .jar extension.

    Application client module: It contains the application client, a standalone Java program that runs on the client machine and interacts with the J2EE application. It also includes the application client deployment descriptor, which defines the configuration and behavior of the application client. It is packaged as a JAR file with a .jar extension.

    Resource adapter module: It contains the resource adapter, a software that enables the J2EE application to access and interact with external systems, such as legacy systems, databases, messaging systems, etc. It also contains the resource adapter deployment descriptor, which defines the configuration and behavior of the resource adapter. It is packaged as a JAR file with a .rar (Resource Adapter Archive) extension.

    What are the types of J2EE clients?

    J2EE defines four types of clients:


    Applet: It is a J2EE component that runs on the web browser and interacts with the J2EE application using the HTTP protocol. It can also access the J2EE services using the RMI-IIOP protocol.

    Application client: A standalone Java program runs on the client machine and interacts with the J2EE application using the RMI-IIOP protocol. It can also access the J2EE services using the JNDI, JDBC, JMS, JAX-RPC, etc. APIs.

    Java Web Start client: A Java program runs on the client machine and interacts with the J2EE application using the HTTP or HTTPS protocol. It can also access the J2EE services using the JNDI, JDBC, JMS, JAX-RPC, etc. APIs. It is launched by the Java Web Start technology, which downloads, caches, and executes the client program from a web server.

    Wireless client: A device that runs on a wireless network and interacts with the J2EE application using the HTTP or HTTPS protocol. It can also access the J2EE services using the JAX-RPC API. It uses the Java 2 Micro Edition (J2ME) technology, which provides a subset of the Java platform for small devices.

    What are the types of enterprise beans?

    Enterprise beans are the server-side components that handle the business logic and data access of the J2EE application. They are managed by the EJB container, which provides services such as security, transaction management, concurrency control, etc., for the enterprise beans. There are three types of enterprise beans:


    Session bean: A stateful or stateless component represents a single client-server interaction or a conversational state with a client. It performs a task or a business process for the client and does not persist any data beyond the scope of the interaction or the conversation. Local or remote clients can access it.

    Entity bean: It is a persistent component representing a business object or an entity in a database. It performs the data access and manipulation for the client and persists the data across multiple interactions or conversations. Local or remote clients can access it. It can be container-managed or bean-managed.

    Message-driven bean: It is a stateless component that acts as a message consumer and producer. It performs a task or a business process based on the messages it receives from a message queue or a message topic. It does not persist any data beyond the scope of the message processing. It can be accessed only by the JMS API.

    What are the types of session beans?

    Session beans are the stateful or stateless components that represent a single client-server interaction or a conversational state with a client. There are two types of session beans:


    Stateful session bean: It is a session bean that maintains a conversational state with a client across multiple method calls. It can store the state information in its instance variables and access it in any method. The container can passivate it to free the memory and can be activated later to resume the conversation. It is bound to a specific client and cannot be shared by multiple clients.

    Stateless session bean: It is a session bean that does not maintain a conversational state with a client. It does not store any state information in its instance variables and cannot access the state information in any method. The container cannot passivate it and is always ready to serve the requests. It is not bound to a specific client and can be shared by multiple clients.

    What are the types of entity beans?

    Entity beans are the persistent components representing a business object or an entity in a database. There are two types of entity beans:


    Container-managed persistence (CMP) entity bean: It is an entity bean that delegates the responsibility of data access and manipulation to the container. It does not contain any code for data access and manipulation and relies on the container to perform these operations. It defines the mapping between the bean fields and the database columns in the EJB deployment descriptor. It can use the EJB QL (Query Language) to perform queries on the database.

    Bean-managed persistence (BMP) entity bean: It is an entity bean that takes the responsibility of data access and manipulation by itself. It contains the data access and manipulation code and performs these operations using the JDBC API. It does not define the mapping between the bean fields and the database columns in the EJB deployment descriptor. It can use SQL (Structured Query Language) to perform queries on the database.

    What are the advantages and disadvantages of CMP and BMP entity beans?

    CMP and BMP entity beans have the following advantages and disadvantages:


    CMP entity beans have the following advantages:

    •They are easier to develop and maintain as they do not contain any code for data access and manipulation.

    •They are more portable and interoperable as they do not depend on any specific database or SQL dialect.

    •They are more efficient and scalable using the container's caching and pooling mechanisms.

    CMP entity beans have the following disadvantages:

    •They are less flexible and customizable as they rely on the container to perform data access and manipulation.

    •They are less powerful and expressive as they use the EJB QL, which is a limited and abstract query language.

    BMP entity beans have the following advantages:

    •They are more flexible and customizable as they perform data access and manipulation by themselves.

    •They are more powerful and expressive as they use SQL, which is a rich and concrete query language.

    BMP entity beans have the following disadvantages:

    •They are more challenging to develop and maintain as they contain the code for data access and manipulation.

    •They are less portable and interoperable as they depend on a specific database and SQL dialect.

    •They are less efficient and scalable as they do not use the container's caching and pooling mechanisms.

    What are the types of servlets?

    Servlets are the web components that handle the requests and responses between the web browser and the web server. They are written in Java and run on the servlet container, which provides services such as security, concurrency, life cycle management, etc., for the servlets. There are two types of servlets:


    Generic servlet: It is an abstract class that implements the Servlet interface and provides the basic functionality for handling any request. It has a service method that receives a ServletRequest object and a ServletResponse object as parameters and performs the request processing. It can be subclassed to create custom servlets for different protocols, such as HTTP, FTP, SMTP, etc.

    HTTP servlet: It is a subclass of Generic servlet that provides the specific functionality for handling HTTP requests. It has a service method that receives an HttpServletRequest object and an HttpServletResponse object as parameters and dispatches the request to the appropriate doXXX method, such as doGet, doPost, doPut, doDelete, etc. It can be subclassed to create web applications that use the HTTP protocol.

    What are the types of JSP elements?

    JSP stands for JavaServer Pages. It is a technology that allows the creation of dynamic web pages containing HTML and Java code. JSP pages are compiled into servlets by the JSP container and executed on the web server. JSP pages contain various elements that define the structure and behavior of the web page. There are four types of JSP elements:


    Directive: It is an element that provides instructions to the JSP container about the page settings, such as page language, content type, import statements, error page, etc. It has the syntax <%@ directive attribute="value" %>.

    Scriptlet: It is an element containing Java code executed when the page is requested. It has the syntax <% Java code %>.

    Expression: An element containing Java code that is evaluated, and the result is inserted into the output stream. It has the syntax <%= Java code %>.

    Declaration: It is an element that contains Java code that declares variables or methods that can be used in the scriptlets or expressions. It has the syntax <%! Java code %>. 

Interested about J2EE?
Get in touch with training experts Get Free Quotes
Leave a comment
Get some additional training from
our expert trainer to learn
Get a job nearby! Upload Resume
  • doc, docx, pdf are allowed
  • US (+1)
Upload your resume