Jee Final
Jee Final
Jee Final
The J2EE platform provides various container types that provide a runtime environment for different types of components. The
containers provide a range of services such as transaction management, security, and resource pooling, and manage the lifecycle of the
components.
4. Explain about distributed multitiered applications with a neat diagram(3-tier architecture). (8) 19
Explain in detail about various Tiers available in systems architecture. (8) 21,20
Write short note on Business tier components.(4) 19
Distributed multitiered applications are applications that are divided into multiple tiers or layers that are distributed across different
physical or logical servers. This architecture provides several benefits, including scalability, reliability, and flexibility.
In J2EE, the architecture of distributed multitiered applications is typically organized into four tiers: client, web, business, and
enterprise information system (EIS).
Scope Accessed over the internet/intranet Designed for internal network use
Standards/Technologies Servlets, JSP, JSF, etc. EJB, JPA, JMS, JTA, etc.
Unit - II
7. (i)What are Servlets? What are the major tasks done by Servlets? (8) 21 20
Servlets are Java-based server-side components used to develop web applications that run on a web server or application server. They
receive requests from web clients, process them, and return responses to the clients. Servlets are managed by a container that provides
various services such as thread management, lifecycle management, security, and other services.
Purpose Used to create web pages with dynamic content Used to handle dynamic requests and responses
Coding Style Page-centric (HTML + Java code) Code-centric (Java code + HTML as strings)
Client Interaction Used for view generation for client interactions Used for handling client requests and responses
Syntax Use <% ... %> syntax for Java code embedding Use Java code directly inside methods
Dynamic web pages, view rendering, template Web application development, RESTful services, and
Use Cases
engines, MVC frameworks, and form processing dynamic content delivery
10. Explain the life cycle methods of a Servlet with a neat diagram
The life cycle of a Servlet is the sequence of stages that a Servlet goes through from its initialization to its destruction. Understanding
the life cycle of a Servlet is important because it helps in understanding how a Servlet processes incoming requests and generates
responses.
Here is a diagram that shows the different stages in the life cycle of a Servlet:
+---------------+ +---------------+
|Initialization| | Destruction |
| (init() ) | | (destroy()) |
+---------------+ +---------------+
^ ^
| |
+---------------+ +---------------+
| Service | | Waiting |
| (service()) | | (no requests) |
+---------------+ +---------------+
11. How to handle Sessions using Servlets? Explain with syntax and examples.(8) 21 20
Explain how session tracking is accomplished in Servlets.
Session tracking in Servlets is the process of maintaining the state of a user's interaction with a web application across multiple
requests. This is important because HTTP is a stateless protocol, meaning that each request/response cycle is independent of previous
and future requests. Servlets use a technique called session tracking to maintain state and keep track of user activity.
Reading a Cookie:
To read a cookie in a Servlet, you need to retrieve it from the request object. For example, the following code retrieves the "username"
cookie from the request:
Cookie[] cookies = request.getCookies();
if (cookies != null)
{
for (Cookie cookie : cookies)
{ if (cookie.getName().equals("username"))
{ String username = cookie.getValue();
// do something with the username
}}}
Writing to a Cookie:
To update the value of a cookie in a Servlet, you need to create a new cookie with the same name and updated value, and then add it to
the response object. For example, the following code updates the value of the "username" cookie to "Jane":
Cookie updatedCookie = new Cookie("username", "Jane");
response.addCookie(updatedCookie);
Deleting a Cookie:
To delete a cookie in a Servlet, you need to create a new cookie with the same name and a maximum age of 0, and then add it to the
response object. For example, the following code deletes the "username" cookie:
Cookie deletedCookie = new Cookie("username", "");
deletedCookie.setMaxAge(0);
response.addCookie(deletedCookie);
13. Explain about Client Http Request and Server Http Response. (HttpServletRequest (4) 19)
In a J2EE web application, the client sends an HTTP request to the server, and the server sends back an HTTP response.
14. Write code to show how a Servlet reads the form parameters.
How are Form data processed by Servlets? Explain with examples. (8) 21
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
PrintWriter out = response.getWriter(); // Get the PrintWriter object to write the response
Suppose we have two servlets - MyServlet1 and MyServlet2. We want to forward a request from MyServlet1 to MyServlet2 and
include the response from MyServlet2 in the response sent back to the client.
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
After MyServlet2 processes the request, it returns the response to MyServlet1. MyServlet1 then includes the response from
MyServlet2 in the current response using the include method of the RequestDispatcher interface.
Finally, MyServlet1 outputs some additional text to complete the response. Note that this text is sent to the client after the response
from MyServlet2 is included, since the include method does not return control to MyServlet1 until the included response is complete.
Unit - III
16. Explain the importance of JSP technology. Draw the Model architecture of JSP.
Give the Model I and Model II architecture of JSP. 21
Model I architecture : - Model I architecture is also known as the JSP-only architecture, in which JSPs are used to implement the
entire application, including handling requests, processing business logic, and generating the response. This architecture is suitable for
small-scale applications with simple functionality.
Model I architecture Model II architecture
+----------+ +----------+
Request | Client |------->| Servlet |
+----------+ +----------+
|
+-----------+ v
| JSP | +-----------+
| (View) | | Model |
+-----------+ +-----------+
| Logic | |
|(Servlet) | v
+-----------+ +-----------+
| DAO | | View |
+-----------+ +-----------+
|Database | |
+-----------+ v
+-----------+
| Response |
+-----------+
Model II architecture: -Model II architecture, also known as the Model-View-Controller (MVC) architecture, is a more robust
approach that separates the application logic into distinct components: Model, View, and Controller.
1. JSP Compilation: The first phase of the JSP life cycle is compilation. When a JSP is first accessed by a client, the JSP
container checks to see if the JSP has already been compiled. If the JSP has not been compiled, the container compiles the
JSP into a servlet.
2. JSP Initialization: After the JSP has been compiled into a servlet, the container initializes the servlet. The initialization
phase involves calling the jspInit() method of the servlet, which can be used to perform any necessary setup tasks.
3. JSP Execution:Once the servlet has been initialized, it is ready to handle client requests. The container calls the
_jspService() method of the servlet for each request, passing in the HTTP request and response objects.
4. Request Handling and Page Processing: The _jspService() method is responsible for handling the client request and
generating the dynamic content of the JSP. During this phase, the servlet retrieves any necessary data from the server and
generates HTML output that is sent back to the client.
5. HTTP Response Generation: Once the dynamic content of the JSP has been generated, the servlet creates an HTTP
response and sends it back to the client. This response includes the HTML content generated by the JSP, as well as any
necessary HTTP headers.
6. JSP Destroyed: The final phase of the JSP life cycle is destruction. When the JSP container shuts down or when the JSP is
no longer needed, the container calls the jspDestroy() method of the servlet, which can be used to perform any necessary
cleanup tasks.
7. Request Handling and Page Processing (Continued): If another request comes in for the same JSP, the servlet can use a
cached version of the compiled servlet, skipping the compilation phase and moving directly to the initialization phase.
18. Differentiate between include directive and include action element with an example for each. (8) 18
In JSP, both include directive and include action element are used to include the content of one JSP page in another JSP page.
There are three scripting elements in JSP: scriptlets, expressions, and declarations.
1. <% %> - Scriptlet:: Scriptlets are used to include Java code directly into a JSP page. They are placed within <% ... %> tags.
Here's an example of a scriptlet that prints out the current date:
<%String name = "John";
out.println("Hello, " + name + "!");
%>
2. <%= %> - Expression: Expressions are used to embed the value of a Java expression directly into the HTML output of a
JSP page. They are placed within <%= ... %> tags.
Here's an example of an expression that prints out the value of a variable:
<p>Today is <%= new java.util.Date() %></p>
3. <%-- --%> - Comment: The comment element is used to include comments in the JSP code that are not included in the
output. Here is an example:
<%-- This is a comment --%>
4. <%! %> - Declaration:The declaration element is used to declare a variable or a method that can be accessed from the
other parts of the JSP page. Here is an example:
<%! int counter = 0; %>
5. jsp:directive.page - Page Directive:The page directive is used to provide information to the JSP container about the
configuration of the JSP page. Here is an example:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
6. jsp:useBean - Bean Declaration: The bean declaration element is used to declare a JavaBean in the JSP page that can be
used to hold and manipulate data. Here is an example:
<jsp:useBean id="user" class="com.example.User" />
7. jsp:setProperty - Set Property:The set property element is used to set the properties of a JavaBean. Here is an example:
<jsp:setProperty name="user" property="name" value="John" />
8. jsp:getProperty - Get Property:The get property element is used to retrieve the value of a property of a JavaBean. Here is
an example:
<p>Hello, <%= ((com.example.User) pageContext.findAttribute("user")).getName() %>!</p>
<jsp:getProperty name="user" property="name" />
20. Write a JSP program to illustrate passing parameters via request header. (8) 18
<%@ page language="java" %>
<%
String name = request.getParameter("name");
String email = request.getParameter("email");
%>
<!DOCTYPE html>
<html>
<head>
<title>Passing Parameters via Request Header Example</title>
</head>
<body>
<h1>Passing Parameters via Request Header Example</h1>
<p>Name: <%= name %></p>
<p>Email: <%= email %></p>
<%
// set parameters in the request header
response.setHeader("name", name);
response.setHeader("email", email);
%>
</body>
</html>
In this example, the JSP program first retrieves the parameters "name" and "email" from the request object using the getParameter()
method. It then displays the values of these parameters using the JSP expression <%= %>.
The program then sets the parameters "name" and "email" in the response header using the setHeader() method. These parameters can
then be accessed by the client via the response header.
This code creates a new cookie with the name "username" and a value of "JohnDoe". The response.addCookie() method is then called
to add the cookie to the response, which will be sent back to the client's browser.
Modifying a Cookie:
To modify a cookie, you can create a new cookie with the same name and a new value, and then add it to the response object.
In this example, the loop iterates through all the cookies stored in the current request and checks if any cookie has the name
"username". If a cookie with the name "username" is found, its value is changed to "jane" using the setValue() method, and the
modified cookie is added to the response object using the addCookie() method.
Deleting a Cookie:
To delete a cookie, you can create a new cookie with the same name and a max age of 0, and then add it to the response object.
In the below example, the loop iterates through all the cookies stored in the current request and checks if any cookie has the name
"username". If a cookie with the name "username" is found, its max age is set to 0 using the setMaxAge() method, and the modified
cookie is added to the response object using the addCookie() method. When the browser receives the response, it will delete the cookie
from its cache.
To read(Retrieving ) a cookie, Modifying a Cookie: Deleting a Cookie:
● The id attribute specifies the name of the variable to which the JavaBean object will be assigned.
● The class attribute specifies the fully qualified class name of the JavaBean object to be created.
● The scope attribute specifies the scope of the variable. It can have one of the following values: page, request, session, or
application.
2.Using JSTL (JavaServer Pages Standard Tag Library): 3. Using EL (Expression Language):
<%-- Import the JSTL core library --%> <%-- Store data in the session --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% session.setAttribute("username", "John Doe"); %>
<%-- Store data in the session --%> <%-- Retrieve data from the session --%>
<c:set var="username" scope="session">John Doe</c:set> ${sessionScope.username}
Unit - IV
25. Discuss about the different types of JDBC drivers.
Elaborate the four types of JDBC drivers. (Type 1,2,3, and 4 drivers neat dia )(8) 18 20 21
What are drivers in JDBC? How many types of Drivers are available in JDBC and which one is suitable for what purposes?
In J2EE (Java 2 Enterprise Edition), JDBC (Java Database Connectivity) drivers are software components that allow a Java
application to interact with a specific database management system (DBMS). JDBC drivers implement the JDBC API, which provides
a standard interface for Java applications to access databases.
Here's an example code snippet that illustrates how to navigate a ResultSet object's contents using the above methods:
try {
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM employees");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
double salary = rs.getDouble("salary");
System.out.println("ID: " + id + ", Name: " + name + ", Salary: " + salary);
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
In the above example, we first create a ResultSet object by executing a SQL query using a Statement object. We then use the next()
method to move the cursor to the next row and retrieve the column values using the getInt(), getString(), and getDouble() methods.
Finally, we close the ResultSet, Statement, and Connection objects in the reverse order of their creation.
29. Write a simple Servlet code to retrieve all the records from a Student relational table (8) 21
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Execute the SQL query to retrieve all records from the Student table
ResultSet rs = stmt.executeQuery("SELECT * FROM Student");
out.println("</body></html>");
out.close();
}
}
This servlet code first sets the content type of the response to "text/html" and then connects to a MySQL database using JDBC driver.
It then creates a statement object to execute SQL queries and retrieves all records from the "Student" table using a SELECT query.
Finally, it displays the records in an HTML table using PrintWriter object.
2. CallableStatement: The CallableStatement interface is used to execute stored procedures. It represents a call to a stored
procedure in the database. The CallableStatement object is created using the prepareCall() method of the Connection
interface. It can take input parameters, output parameters, and return values.
3. PreparedStatement: The PreparedStatement interface is a subinterface of the Statement interface. It is used to execute a
precompiled SQL statement with one or more parameters. The PreparedStatement object is created using the
prepareStatement() method of the Connection interface.
PreparedStatements are used to improve performance and security by separating the logic of SQL statements from the data.
Instead of concatenating data values into the SQL statement, PreparedStatements use placeholders for data values that are
provided later. This separation reduces the risk of SQL injection attacks, where an attacker injects malicious code into the
SQL statement.
The PreparedStatement interface provides various methods to set values to the placeholders and execute the SQL statement. Some
commonly used methods are:
1. setInt(int parameterIndex, int value) - sets an integer value to the specified placeholder in the SQL statement.
2. setString(int parameterIndex, String value) - sets a string value to the specified placeholder in the SQL statement.
3. setDouble(int parameterIndex, double value) - sets a double value to the specified placeholder in the SQL statement.
4. executeQuery() - executes the SQL statement and returns a ResultSet object.
Here is an example of using PreparedStatement to retrieve all the records from a Student relational table in J2EE:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
// Open a connection
conn = DriverManager.getConnection(DB_URL, USER, PASS);
This data type represents a fixed-point decimal value with a specified precision
DECIMAL java.sql.Types.DECIMAL
and scale.
TIMESTAMP java.sql.Types.TIMESTAMP This data type represents a date and time value.
BLOB java.sql.Types.BLOB This data type represents a binary large object, such as an image or audio file.
CLOB java.sql.Types.CLOB This data type represents a character large object, such as a text file.
It is important to note that some databases may not support all of the above data types, and may have additional data types that are not
listed here. In such cases, it is important to consult the database documentation to determine the appropriate mapping.
For example, if we have a SQL table named "employees" with columns "id" (INTEGER), "name" (VARCHAR), "salary"
(DECIMAL), and we want to retrieve data from it using a PreparedStatement, we can use the following code:
Unit-V
32. Brief the different types of EJB with diagrams.
In J2EE, there are three types of Enterprise JavaBeans (EJB) -
1. Session Beans:
● Session beans represent a single client session and are used for implementing business logic in an application. There are two
types of session beans - stateless and stateful.
● Stateless session bean: It does not maintain any state between client-invoked methods. It is used for performing operations
that do not depend on the state of the client.
● Stateful session bean: It maintains the conversational state between the client and the bean. It is used for maintaining
information that persists across the multiple method invocations of a particular client.
Here's a diagram showing the architecture of session beans , Entity Beans, Message-driven Beans-
Session Beans: Entity Beans: Message-driven Beans:
-------------------- -------------- -------------------
| Client |
| Client | | Message |
---------------------
-------------- | Queue |
|
| -------------------
v
v |
--------------------
-------------- v
| Session Bean |
| Entity | --------------
--------------------
| Bean | | MDB |
| Invokes
-------------- | Bean |
v | Interacts with --------------
-------------------- v | Listens to
| Database | -------------- v
-------------------- | Database | --------------------
-------------- | Message-driven |
| Architecture |
--------------------
2. Entity Beans:
● Entity beans represent persistent data in a database. They are used to represent data in a database table and provide an
object-oriented view of the data.
● Container-managed persistence (CMP) entity bean: It maps the entity bean fields to database columns automatically.
● Bean-managed persistence (BMP) entity bean: It requires the developer to write the persistence code manually.
3. Message-driven Beans:
● Message-driven beans (MDB) are used for messaging-based applications. They are triggered by the message queue and can
perform specific operations based on the message received.
________________________________________________________
| |
| CLIENT |
|________________________________________________________|
| |
Remote Local
| |
___________________________________________________________
| | | | |
| Web Server EJB Container App Server |
| ________|_____________ ______|_____ __________|________|
| | | | | | | |
| Servlet JSP/JSF JAX-RS Stateful Stateless Singleton |
| Container Container Container Bean Bean Bean |
|_________________________________________________________________|
Explanation:
● The client can be any application that uses the EJB architecture to access enterprise-level applications.
● The Web server acts as a front-end to the EJB container, handling requests from clients and delegating them to the
appropriate container.
● The EJB container is the core of the EJB architecture. It is responsible for managing EJBs, providing services such as
transactions, security, and persistence, and communicating with the application server.
● The App server provides additional services such as clustering, load balancing, and failover.
● The different types of EJBs are Stateful, Stateless, and Singleton. Each type has its own unique characteristics and use cases.
Context Doesn't maintain any state information for the client. Maintains state information for the client.
Instance Creation One instance is created for multiple clients One instance is created for each client
Easy to scale as it doesn't maintain client-specific state Difficult to scale as each instance is maintained
Scalability
information. for a single client.
Suitable for business logic that doesn't require to maintain Suitable for business logic that requires to
Use case
client-specific data. maintain client-specific data.
35.Explain the Component Pooling and Lifecycle Management service provided by the EJB container.
The EJB container provides component pooling and lifecycle management services to manage the lifecycle of EJBs. These services
ensure that the EJBs are properly initialized, activated, and passivated, as well as optimized for resource utilization.
The following are the key features of component pooling and lifecycle management service provided by the EJB container:
1. Pooling: The EJB container maintains a pool of instances of each type of EJB, depending on the demand. This helps to
minimize the overhead associated with creating and destroying instances of EJBs for every client request.
2. Activation and Passivation: The EJB container activates an EJB instance when it is needed by a client and passivates it
when it is not needed. The EJB container transfers the EJB instance from the memory to the disk to free up the memory
space. This helps to conserve system resources and optimize performance.
3. State Management: The EJB container provides automatic state management for stateful session beans. The EJB container
stores the state of the bean in a persistent storage area and restores it when the bean is reactivated.
4. Concurrency: The EJB container provides a mechanism for managing concurrency among multiple clients accessing the
same EJB. This ensures that the EJB can handle multiple requests simultaneously, without creating conflicts.
5. Transactions: The EJB container manages transactions for the EJBs, ensuring that they are properly committed or rolled
back.
36. Explain the Client Session Management service provided by the EJB container.
The Client Session Management service provided by the EJB (Enterprise Java Beans) container is responsible for managing the client
sessions and maintaining their state. The following are the key aspects of this service:
1. Session management: The EJB container creates and manages the sessions between the client and the server. It provides
session management services such as session creation, session timeout, and session removal.
2. Stateful session bean management: The EJB container manages the state of the stateful session beans (SFSBs) for the
clients. It creates, removes, and maintains the SFSBs as required.
3. Client context propagation: The EJB container provides a client context propagation service that allows the client's security
credentials and other contextual information to be propagated to the server during the session.
4. Concurrency control: The EJB container provides concurrency control mechanisms to ensure that only one client can access
a stateful session bean at a time.
5. Transaction management: The EJB container provides transaction management services to manage the transactions across
the distributed components.
6. Exception handling: The EJB container provides exception handling services to handle the exceptions thrown by the
components and propagate them to the appropriate client.
37. Explain the Database Connection Pooling service provided by the EJB Container.
In J2EE, the Database Connection Pooling service provided by the EJB (Enterprise JavaBeans) container is a mechanism that enables
efficient management of database connections within an application server.
When an application server receives a request that requires a database connection, the server can use a connection from the pool rather
than creating a new one each time. This approach saves time and resources by avoiding the overhead of establishing a new connection
for every request.
The Database Connection Pooling service maintains a pool of preconfigured database connections that can be reused by multiple
clients. The EJB container manages the lifecycle of these connections, acquiring and releasing them as necessary, based on the
requirements of the application.
Typically, the size of the connection pool is configurable, allowing the server to adjust the number of connections based on the
expected workload. The EJB container also provides monitoring and management capabilities for the connection pool, allowing
administrators to view statistics on pool usage, tune performance, and detect and respond to connection failures.
38. Explain the Transaction Management service provided by the EJB container.
In J2EE, the Transaction Management service provided by the EJB (Enterprise JavaBeans) container is a mechanism that ensures data
integrity and consistency in a distributed, multi-tier application environment.
A transaction is a sequence of operations that must be executed as a single, atomic unit. The Transaction Management service ensures
that if any part of the transaction fails, the entire transaction is rolled back to its previous state, ensuring that the data remains
consistent and that there are no partial updates or inconsistencies in the application's data.
The EJB container provides a comprehensive set of APIs for managing transactions in a distributed environment, including the ability
to define transactional boundaries, manage transactional resources, and coordinate transactions across multiple components.
Transaction management is provided by the EJB container through two main components: the Transaction Manager and the Resource
Manager. The Transaction Manager is responsible for managing the overall lifecycle of a transaction, including beginning,
committing, and rolling back transactions. The Resource Manager is responsible for managing transactional resources such as
databases, message queues, and other resources required by the application.
The Transaction Management service is highly configurable, allowing developers to define the behavior of transactions based on the
requirements of their application. For example, developers can choose to use a two-phase commit protocol to ensure that all
transactional resources are either committed or rolled back, or they can choose to use a more relaxed approach, allowing some
transactional resources to be committed while others are not.
39. Explain the Authentication and Access Control service provided by the EJB Container.
In J2EE, the Authentication and Access Control service provided by the EJB (Enterprise JavaBeans) container is a mechanism that
ensures that only authorized users can access and interact with the resources of an application.
Authentication is the process of verifying the identity of a user, typically through the use of usernames and passwords, certificates, or
other forms of authentication. The EJB container provides a flexible and extensible framework for implementing authentication,
allowing developers to choose from a wide range of authentication mechanisms based on the requirements of their application.
Access control is the process of defining and enforcing policies that govern which users are authorized to perform specific actions on a
resource. The EJB container provides a robust and configurable access control mechanism that allows developers to define
fine-grained access control policies based on a wide range of criteria, such as user roles, groups, or individual users.
The Authentication and Access Control service is typically implemented using a combination of security realms, security roles, and
permissions. A security realm is a set of users, groups, and authentication mechanisms that are used to verify user identities. A
security role is a named set of permissions that define what actions a user is authorized to perform within an application. Permissions
are typically granted to roles, and roles are then assigned to users, allowing for flexible and granular access control policies.
The EJB container provides a range of tools and APIs for configuring and managing authentication and access control, including the
ability to define security realms, roles, and permissions using XML or annotations, and the ability to configure authentication
mechanisms such as LDAP, Kerberos, or SSL.
41. Differentiate Bean Managed Persistence (BMP) and Container Managed Persistence (CMP)
Here is a table outlining the main differences between Bean Managed Persistence (BMP) and Container Managed Persistence (CMP)
in J2EE:
Bean Managed Persistence (BMP) Container Managed Persistence (CMP)
The entity bean class must explicitly The EJB container provides default implementations for
CRUD operations implement the CRUD (create, read, update, the CRUD operations, and the developer can customize
delete) operations. them using annotations or XML configuration files.
BMP can provide better performance in CMP may have slightly more overhead because the
certain scenarios because the developer has container manages the persistence logic, but it can also
Performance
fine-grained control over the persistence provide optimizations and caching that can improve
logic. performance.
BMP can be more difficult to maintain CMP can be easier to maintain because changes to the
Maintenance
because changes to the persistence logic persistence logic can be made using annotations or XML
complexity
require changes to the entity bean class. configuration files without changing the entity bean class.
BMP may be less portable between different CMP can be more portable between different EJB
Portability EJB containers because the persistence logic containers because the persistence logic is managed by
is tightly coupled to the entity bean class. the container.
To illustrate how annotations and dependency injection work together in J2EE, consider the following example:
@Stateless
public class MyService {
@Inject
private MyDAO dao;
@PersistenceContext
private EntityManager entityManager;
Each archive file has a deployment descriptor, which is an XML file that provides configuration information for the application or
module. The deployment descriptor specifies things like security settings, resource references, and initialization parameters.
In J2EE, the deployment descriptor for a JAR file is called ejb-jar.xml, the deployment descriptor for a WAR file is called web.xml,
and the deployment descriptor for an EAR file is called application.xml. The deployment descriptor is typically located in the
META-INF directory of the archive file.
The deployment descriptor is an important part of the deployment process, as it provides critical information to the application server
or web container. Without the deployment descriptor, the server would not know how to configure and deploy the application or
module.