Introduction to J2EE Technologies
J2EE is a short form of Java 2 Enterprise Edition, formerly known as Java 2 Platform Enterprise Edition with a set of specifications extending Java 2 Standard Edition(J2SE). J2EE provides a set of services that are built-in a very large scale, multi-tier, component-based, distributed. Usually, J2EE is a set of APIs that helps in building large-scale applications. J2EE Technology not only uses the APIs but also it is a standard for building and deploying enterprise applications.it promises “write once, run anywhere”.
Java Enterprise Edition includes several specifications that serve various purposes like generating web pages, reading and writing from the database, managing distributed queues.
List of J2EE Technologies
Graphical Representation of the J2EE Platform.
1. Java Servlet
Servlets are the java programs that run on webserver.java servlets used to generate dynamic web pages used to handle the request from a web browser, process the web browser, and send the process to reverse back to the browser.
Common Gateway Interface (CGI) is also used to develop dynamic webpages but CGI has several limitations like performance, scalability, reusability, etc….. To overcome this limitation we can use servlet.
One of the most important drawbacks of CGI is- every time any new request from the user CGI program handles it by creating a new process. If a large number of users increases then CGI has to create a new process for every request, creating new for each process is not valid for the server-side because has limited resources. In comparison to CGI and servlet-Unlike CGI, servlet programs are handled by separate threads.
Servlet Execution Process:
- The client sends a request.
- The web server receives the request.
- The web server passes requests to the corresponding servlet.
- Servlet processes request and generate response in the form of output.
- Servlet sends a response back to a web server
- Web server sends response to client.
2. Java Server Pages (JSP)
Java Server Pages is server-side programming used to create dynamic web pages and build web-based applications.
Features of JSP
- JSP performance is significantly increased, because it allows the user to embed java code within HTML.
- Like servlet JSP also has access to Enterprise Java APIs
- JSP pages are also used with the combination of servlets.
- JSP tags which allows embedding java code with HTML are <%—–JSP code—- %>
- Embedding JSP code within HTML makes HTML pages dynamic like-registration forms, dropdown boxes, etc.
- JSP is used to access Java Beans Objects.
- JSP separates the presentation layer from Business Logic.
- Provides the easiest way to generate dynamic web pages compared to servlets.
- Any changes in JSP code is handled within web container, it doesn’t require recompilation.
- Like servlets JSP [does not require additional files Class Files and web,xml .
- Additional web.xml mapping is not necessary for JSP.
Architecture of JSP
Working of Architecture #1
In this architecture, JSP plays an important role in processing client requests.
- A client sends request to JSP
- JSP Creates JavaBean Object.
- JavaBeans process request using necessary data from database if required.
- The response is sent back to the client.
Working of Architecture #2
In this architecture, Servlet plays an important role. Servlet acts as a controller.
- The client sends request.
- Servlet processes the request sent by the client.
- Servlet is responsible for creating a bean object and calls a specific JSP page.
- Here JSP does not process any client request.
- JSP just performs the presentation part.
3. Enterprise Java Bean (EJB)
Enterprise Java Beans is a development architecture for building highly scalable and robust enterprise-level applications.
Features of EJB
- The developer has to focus on the business logic of the application. Since the application server provides most of the system-level services Transaction, Logging, exception handling, etc.
- EJB container manages all EJB instances.
- EJB components run on any compliant EJB compliant server these benefits on platform-independent.
Types of Enterprise Beans
Types of enterprise beans are:
1. Session Bean
Session beans performs the task for client. Encapsulates the business logic can be invoked programmatically by client.
There are three types of session beans:
- Stateful Session Bean: Instance of Stateful session bean represents the state of unique client, often called conversational state. It is also called interactive session and it is associated with only one user. State is retained once the client removes beans session ends and state disappears.
- Stateless Session Bean: Stateless session instance does not maintain a conversational state with client. When client invokes method of stateless bean variable contain specific to that client but only for duration of invocation. The instance applies to all clients. Can implement a web service.
- Singleton Session Bean: Instantiated once for per application and exist for lifecycle of application. Used in circumstances where single instance bean shared all across concurrent clients. Maintains states between client invocations, but not required to maintain state across server shutdowns. Should be instantiated upon application start-up.
2. Message Driven
Message-driven bean acts as a listener for a particular message types such as java message server API.
4. Java Database Connectivity (JDBC)
Java Database Connectivity is a Java API used to connect and execute queries.it uses JDBC drivers for connectivity.
Types of Drivers
- JDBC-ODBC Bridge driver
- Native Driver.
- Network Protocol Driver.
- Thin Driver.
- ODBC uses ODBC drivers for connection since these are platform-dependent that is reason why java developed own JDBC API.
- Java can be used to write different type’s executables this includes- Java Applets, JSP, EJB, Servlets, etc.
JDBC architecture is divided into two types
- Two-tier architecture.
- Three-tier architecture.
Graphical representation of Two-Tier Architecture.
In this two-tier architecture java application directly access from database. Client access data directly with the use of the JDBC driver. The database may be located in the same machine or another machine in a client-server configuration.
Graphical representation of Three-Tier Architecture.
In this architecture commands are sent to the middle tier, it processes the request and then forwarded to the data source. Data source processes the request and results sent back to the middle tier, which then sent to the user. Three-tier maintains control over data access and update made to corporate data.
5. Java Message Service (JMS)
Java Messaging Service is an API that provides formal communication between computers in network that is called Messaging Service.
- Exchanging of messages can be synchronous or asynchronous mode.
- JMS API allows interoperability between other java platform languages.
- Applications are built on concept message queue, sender, and receiver.
There are two types of messaging domains in JMS
1. Point-to-point messaging domain
- Applications are based on concept of queues sender and receiver.
- Each message sent to a messaging queue receiver stores messages in the messaging queue.
- Queue stores all messages until it consumes or expire.
- If the receiver is not available in a network the message will remain, message broker until the receiver consumes the message.
- The receiver acknowledges the message consumption.
2. Publish / Subscribe Messaging Domain
- Applications sends message to message broker called topic.
- Topic publishes message to all subscribers.
- Topic retains all messages until it consumed by receiver.
- Here multiple consumers and consumers will get message after subscribed.
6. Java Transaction API (JTA)
JTA allows performing distributed transactions that are to access and update data by multiple computers in a network. JTA API act as a java interface between Transaction Manager and client.
The application server and resource manager controls access in shared resources transactions.
- Atomicity: The transaction manager is responsible for making a final decision either to commit or roll back.
- Provides consistency: If a transaction fails data integrity is preserved.
- Not possible to phases of the transaction until transaction by other applications or threads is committed or rolled back.
- Committed can be preserved even in case of system failure.
- Three types of transaction Managers.
- Database: transactions prevent the database to be left in an inconsistent state due to an incomplete update.
- JMS providers-use of transactions ensures messages are delivered reliably.
- J2EE connector Architecture components.
- Container Managed Transactions: EJB container sets the boundaries of the transaction, can be used with any type of enterprise bean and code does not include statements that begin and end transaction.
- Component Managed Transaction: Transactions are managed by JDBC API, which allows transaction management in the application itself. Message-driven beans explicitly mark the boundaries of transactions.
7. Java Mail
Java Mail is API this allows us to compose, read and write emails. This API provides protocol-independent and platform-independent.
Protocols used with Java Mail API
- SMTP: SMTP is a simple mail Transfer Protocol is a mechanism used to transfer emails. Apache server, mail server, etc. can be used as the SMTP server.
- POP: POP is Post Office Protocol /POP3 it is a mechanism to receive the email. Supports a single mailbox for each user. Apache James Server, the mail server can be used as POP.
- IMAP: Internet Message Access Protocol is an advanced protocol for receiving messages. Supports multiple mailboxes for each user.
- MIME: Multiple Internet Mail Extension tells the browser what is being sent like the format of the email, attachments, etc.
Java Mail Architecture
8. Java Naming and Directory Interface (JNDI)
Java Naming and Directory Interface is an API for Naming and Directory Service allows the user to discover data using specific names.
- JNDI is independent of implementation.
- It provides Service Provider Interfaces (SPI) – allows directory service plugged into the framework.
- API used for connecting java applications to an external directory.
- It provides a mechanism to bind an object to the name.
- The event interface allows clients to determine when directory entries have been modified.
JNDI uses the following naming and directory services.
- Lightweight Directory Access Protocol (LDAP).
- Common Object Request Broker Architecture (CORBA).
- Common Object Services (COS)
- Java Remote Method Invocation (RMI).
- Domain Name Service (DNS).
9. J2EE Connector Architecture (JCA)
JCA used for connecting application server to an EIS.
- JCA enabled application server integrate with any JCA compliant EIS.
- Resource Adapter allows java application to access and interact with resource manager of EIS.
- Also provides message-based transactional integration java EE based web services with EIS.
JCA Defines standard set of system-level contracts between Java Application Server and Resource Adapter. Which are given below-
- Connection Management: Enables application Sever pool connection to EIS Enables application components to connect. This benefits scalable application environment and support large number of clients.
- Transaction Management: Allows an application server to use transaction manager to manage transactions of multiple resource manager. This supports transactions are managed internally, without involving external transaction manager.
- Security Management: Prevents security threats to EIS and protects valuable resources managed by EIS.
- Life Cycle Management: Enables application server to manage the lifecycle of a resource adapter from beginning through termination.
- Work Management: Enables resource adapter to assign work to the application server for execution. Application server dispatches threads to complete assigned work.
- Transaction Inflow Management: Allows the resource adapter propagate imported transactions to application server. Allows resource adapter transmit transaction completion and crash recovery initiated by EIS.
- Message Inflow Management: Allows asynchronously delivery of messages to message endpoints residing application server.
Conclusion – J2EE Technologie
J2EE is optimized for enterprise computing or enterprise applications that give client enhancement. Almost all J2EE technologies provide containers or application servers it helps in fast development and deployment. Since java is platform-independent standards of cross-platform development guaranteed to run on multiple platforms. Most of the technologies in J2EE separate design and development.
This is a guide to J2EE Technologies. Here we discuss the introduction and list of j2ee technologies along with features and architecture of J2EE Technologie. You may also have a look at the following articles to learn more –