Advertisment

New Features in Java EE6

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: Since its avatar as the platform of choice for the enterprises, Java Platform, Enterprise Edition  has become the de facto industry-standard platform for building enterprise-class applications coded in the Java programming language. The new platform is now not only based on a stronger Java Platform, Standard Edition (Java SE), but also associated with APIs, libraries and system services that support the non-functional requirements such as scalability, accessibility, security, integrity, and other requirements of enterprise-class applications.

Advertisment

The new Enterprise Edition

The requirements for the new Java EE 6 platform came essentially from the important goals set by the JCP. We will discuss three of the important goals that makes the new Java EE 6 a better platform for enterprise app development.

Enhanced technology stack:The new Java EE 6 platform introduces the concept of Profiles and Pruning. The concept of profiles entails configurations of the Java EE platform that are designed for specific "class of applications".  A Profile, by definition, includes a subset of Java EE platform technologies, other related technologies that have gone through the JCP, but not essentially a part of the Java EE platform, or a combination of the two. In this edition, Java EE 6 introduces the first of these profiles, called the "Web Profile". As the name itself indicates, the Web Profile is a subset of the Java EE platform designed for web application development. The Web Profile thus includes only those technologies that are needed for most web applications, and does not include the enterprise technologies that applications typically don't need. Pruning is again a new concept in Java EE platform, and is applied to the technology part.

Advertisment

Enhanced extensibility:When newer technologies were available, the Java Platform accommodated them suitably, through the introduction of APIs, libraries and frameworks. However, this is not a very efficient way of accommodating newer technologies, as the platform gets bloated and results in management issues, and is not a scalable solution. The new Java EE 6 platform introduces "extensibility points" and more service provider interfaces. This allows  application developers to "plug in the new technologies" (even frameworks for that matter) in a standard way. Once the new technology is plugged in, these technologies are available as the built-in facilities of the Java EE 6 platform.

In this edition, emphasis on extensibility has been placed on the web tier. As we are aware that web application developers often use home-grown or third-party frameworks for developing web applications, registering these frameworks is an important and complicated step in the earlier edition of the platform. The developers / deployers / implementers often require to add to or edit large and complex XML deployment descriptor files. The new Java EE 6 enables these frameworks to self-register, making it easy to incorporate and configure them in an application.

Ease of development:The new Java EE 6 brings in many usability improvements in many areas of the new platform. For example, we can now use annotations to define servlets and servlet filters. Also, Java EE 6 standardizes a set of annotations for dependency injection, making injectable classes much more portable across frameworks. Furthermore, Java EE application packaging requirements have been simplified. We now can also add an enterprise bean directly to a web archive (WAR) file.

Advertisment

In this work, we will primarily focus on the enhanced technology stack and delve into the details of some of the advanced aspects of the new Java EE 6 platform.

Enhanced technology stack



The new Java EE 6 platform adds a few new technologies that render the platform even more powerful. Three of these are described in the subsequent sections. The new technologies are:

Java API for RESTful Web Services (JAX-RS): We are already aware that Representational State Transfer (REST) is an architectural style, and RESTful web services are web services built according to the REST architectural style. Enabling web services with the RESTful approach has emerged as a popular alternative to using SOAP-based web services technologies mainly due to the fact that REST's lightweight nature and the ability to transmit data directly over HTTP. An important concept in this REST style is the existence of resources, each of which can be associated with a global identifier such as URI. In particular, data and functionality are considered resources that can be identified and accessed through URIs. To manipulate these resources, components of the network, clients and servers, the REST technology allows  us to communicate through a standardized interface such as HTTP and a small, fixed set of verbs such as GET, PUT, POST, and DELETE, and exchange representations of these resources. The new JAX-WS technology enables developers to build lightweight web services that conforms to the REST style of software architecture. JAX-RS furnishes a standardized API for building RESTful web services in Java EE  environment. The API contributes a set of annotations and associated classes and interfaces. Applying the annotations to POJOs enables to expose web resources in a standard way. This approach makes it simple and quick to create RESTful web services in a Java environment. Java EE 6 includes the latest release of the technology, JAX-RS 1.1, which is a maintenance release that aligns JAX-RS with new features in Java EE 6.

Advertisment

Contexts and Dependency Injection for the Java EE Platform (CDI): CDI is a new technology in Java EE 6 environment that "supplies" a powerful "set of services" to Java EE components. These services allow Java EE components to be bound to lifecycle contexts, to be injected, and to interact in a loosely coupled manner by "firing" and "observing" events. Some of the Java EE components that significantly benefit from this are Session EJBs and JSF Managed beans. CDI, this way, unifies and simplifies the EJB and JSF programming models and allows enterprise beans to replace JSF managed beans in a JSF application. In this way CDI technology helps bridge the major gap between the "web tier" and the "business tier" of the Java EE platform.While in the business tier, EJB and JPA technologies provide a strong support for the transactional resources, database operations and persistance, the web tier technologies  focus on the presentation aspects through JavaServer Pages (JSP) and JavaServer Faces (JSF) components and Frameworks. The services of CDI technology bring transactional support to the web tier making it easier for developers to rope in transactional support within the web tier.

Bean Validation



The bean validation aspect in the new Java EE 6 platform makes validation aspect of the web application simpler and reduces the duplication, errors, and clutter that characterizes the way validation is often handled in enterprise applications. The beauty of the new bean validation framework is that the same set of validations can be shared by all layers of an application. The bean validation framework for validating Java classes has been written according to JavaBeans conventions. In fact, developers can use annotations to specify constraints on a JavaBean. A validator class then validates each constraint. The developer can specify which validator class to use for a given type of constraint.

Enhanced Web tier

Advertisment

There has been significant enhancements in the web tier aspect of the new platform. The following are enhancements to the new web tier capabilities:

 

Advertisment

Web Fragments:Web Fragments is an enhancement in the new Servlet 3.0 technology. This technology helps in modularizing the deployment descriptors thereby simplifying the process of accommodating other frameworks such as Spring, Apache Wicket, etc. A web fragment can be considered a logical segment of a web.xml file. Therefore developers can configure multiple web fragments, each representing a logical segment, and the set of web fragments can be viewed as constituting an entire web.xml file. This logical partitioning of the web.xml file enables web frameworks to self-register to the web container.

Shared Framework Pluggability feature:The Shared Framework Pluggability feature in the new platform allows developers to plug in shared copies of frameworks, such as Java API for XML-based Web Services (JAX-WS), JAX-RS and JSF, that are built on top of the web container. This new enhancement comes from the Servlet 3.0 technology that introduces a new interface called ServletContainerInitializer that helps in plugging-in a framework.

JSF 2.0 Framework: The new JFS 2.0 technology provides a server-side component framework that simplifies the development of user interfaces (UI) for Java EE applications. In this latest release of the technology, it is even easier for developers to bring out UI enhancement. One area of particular improvement is page authoring. Authoring a JSF page is much easier in JSF 2.0 through the use of the standard JavaServer Faces View Declaration Language, known as Facelets.

Advertisment

Facelets: In the Facelets approach, developers can use HTML-style templates to present a JSF page and to build component trees, instead of using JSPs. Facelets offers several advantages over JSP. Using JSP, elements in a web page are processed and rendered in a progressive order in the JSF. However, JSF provides its own processing and rendering order. This can cause unpredictable behavior when web applications are executed. Facelets resolves this mismatch. Facelets also enable code reuse through templating and can significantly reduce the time to develop and deploy UIs. Facelets can be authored using XHTML markup language. This allows Facelets pages to be portable across diverse development platforms.

Templating: As the name itself indicates, with templating, developers are able to create a page that acts as a template for other pages in an application. This helps in avoiding creating similarly constructed pages multiple times. Templating feature also helps maintain a standard look and feel in an application with a large number of pages. The Facelets tag library provides a simple set of templating tag, such as , and to take care of different aspects of templating feature.

Composite Components: The new Composite components of JSF 2.0 version makes it easy  for the developers to create customized JSF components. You can create composite components by using JSF page markup, other JSF UI components, or both. Also through the Facelets feature, any XHTML page can become a part of the composite component. In addition, composite components can have validators, converters, and listeners attached to them just like the set of UI components provided by JSF. These components can be storeed in a library and use it as necessary.

Ajax in JSF 2.0: Ajax technology helps web applications retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. To enable this JSF's request processing cycle has been modified and expanded to allow partial page updates and partial view traversal. This new feature in JSF allows one or more components in a view to be visited, potentially to have them pass through either or both the execute phase or render phase of the request processing lifecycle. This new key feature in JSF and Ajax frameworks allows selected components in the view to be processed, rendered, or both.

Enterprise JavaBeans

The new Java EE 6 platform incorporates a new version of Enterprise JavaBeans Technology - EJB 3.1. Some of the significant enhancements over EJB 3.0 are as follows.

No-view interface view: The Local business interfaces feature of EJB 3.0 are now optional in EJB 3.1 version. Now the developers can get the same enterprise bean functionality without having to write a separate business interface. A bean that does not have a local business interface, therefore, exposes a "no-interface view".

Singletons: A Singleton phenomenon ensures the instantiation of an object only once for an application in a particular Java Virtual Machine (JVM). A singleton bean, is also known as a singleton, is a new kind of session bean that is guaranteed to be instantiated once for an application in a particular JVM. Singleton feature allows easily share state between multiple instances of an enterprise bean component or between multiple enterprise bean components in the application. Singleton Session EJBs can be stateless or Stateful beans.

Asynchronous session bean invocation: It is now possible to invoke EJB methods asynchronously. For an asynchronous method invocation, control returns to the client even before the container dispatches the invocation to an instance of the bean. Annotations help in making the method execute asynchronously. The @Asynchronous annotation is used to render a method Asynchronous in nature. The business methods in the EJBs can be associated with the @Asynchronous annotation.

EJB-Lite: EJB-Lite is not a new technology, but a new convenience feature in the new Java EE 6 platform. The objective behind this feature is to offer a subset of EJB 3.1 features that cover the common requirements for the business logic tier of most applications, one that also gives vendors the flexibility to provide EJB technology across a variety of Java EE profiles.

The Persistence API

The JPA technology was introduced in Java EE 5 platform, which provided a POJO-based persistence model for Java EE as well as Java SE applications. JPA handles the details of how relational data is mapped to Java objects, and it also standardizes Object/Relational Mapping (ORM). JPA has been widely adopted and is recognized as the enterprise standard for O/R persistence.

The new platfomr includes JPA 2.0 version which brings in new features and significant enhancements. Some of them are:Object/Relational mapping enhancements, enhanced Java Persistence Query Language, criteria-based query API, and support for Pessimistic Locking.

B V Kumar, director and chief architect, Cognizant Technology Solutions

tech-news