J2EE Interview Questions and Answers

This page provides answers to frequently asked J2EE interview questions.

What is J2EE?

J2EE (Java 2 Platform, Enterprise Edition) is a platform for developing and deploying multi-tier enterprise applications. It's a collection of services, APIs, and protocols that extend the Java platform to enterprise-level needs, providing a robust, secure, and scalable environment.

J2EE Modules

A J2EE module is a software unit containing one or more J2EE components of the same container type, along with a deployment descriptor. Modules are deployable units within J2EE applications.

Types of J2EE Modules

  • Application Client Module
  • Web Module
  • Enterprise JavaBeans (EJB) Module
  • Resource Adapter Module

Application Client Module Contents

  • Class files
  • Client deployment descriptor

Packaged as a JAR file (.jar extension).

Web Module Contents

  • JSP (JavaServer Pages) files
  • Servlet class files
  • Web deployment descriptor
  • GIF and HTML files

Packaged as a WAR file (.war extension).

EJB Module Contents

  • Enterprise bean class files
  • EJB deployment descriptor

Packaged as a JAR file (.jar extension).

Resource Adapter Module Contents

  • Java interfaces and classes
  • Native libraries
  • Documentation
  • Resource adapter deployment descriptor

Packaged as a RAR file (.rar extension).

Main J2EE Application Components

  • Application clients
  • Java Servlet and JSP components (web components)
  • Business components (Enterprise JavaBeans)
  • Resource adapter components

Web Components

Java Servlets and JSPs are considered web components. Servlets handle requests and generate responses dynamically; JSPs provide a template-based approach to creating web pages.

Types of J2EE Clients

  • Applets
  • Application clients
  • Java Web Start clients
  • Wireless clients

Applets

Applets are J2EE components that run within a web browser or other applet-compatible environments.

Containers

Containers provide runtime support for J2EE components, managing lifecycle, security, deployment, and threading.

Applet Containers

Containers specifically designed to support the applet programming model.

Thin Clients

Thin clients are lightweight interfaces that don't handle complex operations like database queries or connections to legacy systems.

JavaServer Faces (JSF)

JSF is a UI framework for Java web applications. It provides reusable UI components and follows the Model-View-Controller (MVC) design pattern.

Enterprise JavaBeans (EJB) Platform

The EJB platform handles tasks like transaction management, state management, resource pooling, multithreading, and simplified database access, allowing developers to focus on business logic.

Deployment Descriptors

Deployment descriptors (XML files) describe a component's deployment settings. Both J2EE applications and their modules have deployment descriptors.

Struts Framework

Struts is an MVC framework using Java Servlets, JSP, custom tags, and message resources for building enterprise applications.

  • Model: Represents the application's data and business logic (often JavaBeans).
  • View: JSP pages display information to the user.
  • Controller: Manages user interactions (ActionServlet is a key component).

Hashtable in J2EE

Hashtable is a synchronized collection of key-value pairs. Unlike HashMap, it's thread-safe but doesn't allow null values or duplicate keys.

Hibernate and HQL

Hibernate is an Object-Relational Mapping (ORM) solution. HQL (Hibernate Query Language) allows you to query databases using object-oriented syntax instead of SQL. Hibernate handles complexities like associations and inheritance.

Hibernate Limitations

  • Potentially slower query execution than optimized SQL
  • Limited HQL support for composite keys
  • No shared references for value types

Hibernate Benefits

  • Database independence (portability)
  • Mapping of domain objects to relational databases
  • JPA (Java Persistence API) support
  • Improved database connectivity compared to JDBC

Object-Relational Mapping (ORM)

ORM maps objects in your Java code to tables in a relational database, simplifying data access and reducing code complexity. It handles data transformations between object and relational representations.

Authorization

Authorization determines if a user (or principal) has permission to access a specific resource or method based on security roles and mappings.

Authorization Constraints

Rules defining who can access web resources.

Hibernate's save() and saveOrUpdate()

  • save(): Persists a new object.
  • saveOrUpdate(): Saves a new object or updates an existing one based on the object's ID.

Hibernate's load() and get()

  • load(): Throws an exception if the object isn't found; never returns null.
  • get(): Returns null if the object isn't found.

Web Container in J2EE

A web container is the runtime environment that supports web components (Servlets and JSPs).

Connection Pooling

Connection pooling reuses existing database connections, improving performance by avoiding the overhead of repeatedly creating and closing connections.

Servlets

Servlets are server-side components that handle requests and generate responses. They are commonly used with HTTP but can support other protocols.

Advantages of ORM

  • Increased developer productivity
  • Improved performance
  • Vendor independence (portability)
  • Easier maintenance

Core Hibernate Interfaces

  • Session
  • SessionFactory
  • Configuration
  • Transaction
  • Query and Criteria

B2B

B2B stands for Business-to-Business.

Hibernate File Extensions

  • Hibernate Mapping File: filename.hbm.xml
  • Hibernate Configuration File: hibernate.cfg.xml

Adding Hibernate Mapping to Configuration

[Describe how to add a Hibernate mapping file to the Hibernate configuration file. This would typically involve specifying the mapping file's location within the configuration file.]

Multi-Tier Architecture Components

  • Presentation Tier: Handles user interface and display.
  • Business Tier: Contains business logic and rules.
  • Resource Tier: Interacts with databases and other resources.

JTA, JNDI, and JMS

  • JTA (Java Transaction API): Manages transactions across systems.
  • JNDI (Java Naming and Directory Interface): Accesses data from directory services.
  • JMS (Java Message Service): Sends and receives messages asynchronously.

J2EE Tiers

  • Client Tier: User interface (browser, app, etc.).
  • Middle Tier: Presentation (JSP), business logic (EJB), and data access.
  • Backend Tier: Enterprise Information System (EIS) storing data.

EAR, WAR, and JAR Files

  • EAR (Enterprise Archive): Contains web, EJB, and client modules (.ear).
  • WAR (Web Archive): Contains web application components (.war).
  • JAR (Java Archive): Contains class and library files (.jar).

Spring Framework

Spring is a lightweight, open-source framework simplifying enterprise application development in J2EE. It was created by Rod Johnson and released under the Apache 2.0 license in June 2003.

Spring Modules

  • Core container
  • Object-Relational Mapping (ORM)
  • Data Access Object (DAO)
  • Application context
  • Aspect-Oriented Programming (AOP)
  • Web
  • Model-View-Controller (MVC)

Action Mapping in Struts

Action mapping configures how URLs map to specific Action classes and their corresponding views (JSP pages) in Struts.

ActionForm in Struts

An ActionForm is a JavaBean that handles data submitted from a form. It's automatically populated on the server-side and manages session state.

Backing Beans in JSF

Backing beans are JavaBeans associated with JSF pages. They manage component properties and handle events, validation, and navigation.

Build Files (Ant)

Build files (typically XML) define targets (sets of tasks) to be executed by Apache Ant, a build automation tool. If no target is specified, the default target runs.

Business Logic

Business logic is the code implementing an application's core functionality. In EJB, this resides within enterprise bean methods.

CDATA Sections in XML

CDATA sections mark text within an XML document that shouldn't be parsed as XML markup. It's used to include text containing XML-like characters without causing parsing errors.

Component Contract

A component contract defines the agreement between a J2EE component and its container, covering lifecycle management, communication, and services provided by the container.

Connectors and Connector Architecture

Connectors provide standardized access to enterprise information systems (EIS). The connector architecture defines contracts that resource adapters must support to integrate with J2EE products.