Show TOC

Background documentationJava Enterprise Edition 5 Overview Locate this document in the navigation structure

 

Java EE 5 offers many improvements to previous J2EE releases. J2EE is traditionally recognized for being very powerful but complex to use. Java EE 5 maintains the powerful features of previous releases and offers more flexibility to the application developer. The main focus of the Java EE 5 specification is ease of development. With Java EE 5, the application developer benefits from simplified application architecture. Most boilerplate code from previous releases is now obsolete and deployment descriptors are optional. Java EE 5 lets the developer focus on implementing the business scenario of the application and shifts more work to the containers providing a set of intelligent defaults for the most common cases. Thus, the application developer configures the fundamental behavior of the application, and deals with details in exceptional cases only.

Annotations

Java EE 5 uses annotations extensively. Everything is declared, expressed, and configured using annotations. Annotations are a special type of modifier in the form of metadata. Annotations precede other modifiers and are represented by an @ sign followed by a set of name-value pairs elements in parentheses. They do not affect program semantics directly, but they do affect how libraries and tools treat program code. Annotations employ the 'declarative programming' approach. Instead of directly specifying a set of rules for the container to execute, annotations supply a set of conditions. The container resolves these conditions and decides how to proceed.

More information about annotations and JSR 250: www.jcp.org.

Dependency Injection

Enterprise Java applications need access to external resources such as enterprise beans, Web services, data sources, and so on. To access such resources in J2EE 1.4, you specify dependencies in a deployment descriptor and obtain a reference to these resources using a JNDI lookup. With dependency injection, component dependencies are automatically injected in the component by the container using annotations. The container also manages the life cycle of injected resources. You do not need to look up resources explicitly.

Enterprise JavaBeans

The main focus of EJB 3.0 is ease of development. EJB 3.0 lets the container do more work and lets the developer focus on implementing the business functions required by the business scenario of the specific application. Many of the requirements of the EJB 2.x programming model have been lifted and thus the EJB architecture and programming model are simplified. EJB 3.0 provides the following new features:

  • As enterprise beans are plain old Java objects, you do not need to implement javax.ejb.xxxBean

  • Component/home interfaces for session beans are now obsolete. Component interfaces are replaced by business interfaces. Clients access bean instances directly through one of its business interfaces. The container handles bean instance creation transparently to the client. Business interfaces are plain java interfaces annotated with the type of access you wish to provide. As the session bean's interface is a plain Java interface, you do not need to extend javax.ejb.EJBObject or EJBLocalObject interfaces.

  • Deployment descriptors are only optional as everything is declared, expressed, and configured using annotations.

  • JNDI lookups are no longer necessary as external resources are obtained using dependency injection.

  • Callbacks are optional and are declared using annotations. You use callback methods to receive notifications for life cycle events of a bean instance. To define interceptor methods for life cycle event callbacks, you use the @PostConstruct, @PreDestroy, @PostActivate, and @PrePassivate annotations.

  • You do not need to separate your application components into DAOs and DTOs.

  • Simplified exception handling

  • Interceptor methods may be defined in the bean class, or in an interceptor class associated with the bean. To use classes as interceptors in enterprise beans, you denote the enterprise bean with the @Interceptors annotation and list the classes to be used.

  • To define business method interceptor methods, you use the @AroundInvoke annotation. You use business method interceptors to modify the parameters or the return value of the method for exception handling, profiling, and so on. The interceptor method shares the security and transaction context with the business method for which it is invoked.

JavaServer Faces

The JavaServer Faces technology allows you to build up dynamic server-generated UI through reusable UI components and management of their state. JSF introduces a standardized approach to component design, thus improving consistency across Web components. JSF is integrated with the JavaServer Pages technology (JSP) 2.1 and both technologies benefit from a unified Expression Language (EL). With JSF, the application developer benefits from easy event handling, input validation, page navigation, and support for internationalization and accessibility.

Unified Expression Language (EL)

With the integration of JSP and JSF, the EL is aligned with the two specifications and now supports both the ${} syntax and the #{} syntax. The EL supports deferred expressions, expressions that set values, expressions that invoke methods, and JSTL iteration tags with deferred expressions.

Servlet 2.5

The main new features in the Servlet 2.5 specification are the use of annotations, resource injection, and some changes to web.xml. In web.xml, you can provide multiple mapping patterns and you can bind all servlets (and JSPs) to one mapping using an asterisk (*). The web.xml also accepts any legal HTTP 1.1 method into the < http-method> element. Thus, you can place security constraints on any HTTP method and the container manages the security for you.

JSP 2.1

With JSP 2.1, you benefit from the integration between JSP and JSF, that is, JSF tags and JSP code are completely aligned.

Java Persistence API

Java EE 5 provides a unified persistence model, the Java Persistence API. The persistence model is not limited to EJBs only. Persistent classes can be used directly in other components, for example, Web applications or components outside the Java EE application server, such as application clients. In the Java Persistence API, entities are Plain Old Java Objects (POJOs) that benefit from a standardized object relational mapping using annotations. Entities support inheritance, polymorphism, and optimistic locking. As entities are POJOs, they can be packaged anywhere in a Java enterprise application.

More information: Overview of the Java Persistence API