Delving into Java EE 6
This topic deserves special attention because of the huge impact Java EE 6 made into the way we develop enterprise Java applications by adding new, powerful technologies and features to its specification. Several topics are mentioned here, and most of them will be demonstrated throughout the next chapters:
Java API for RESTful Web Services (JAX-RS, JSR 311): This enables lightweight web services' development following the Representational State Transfer (REST) architectural paradigm. The concept of manipulating resources through different networks using a standard protocol such as HTTP, is a growing paradigm and an alternative to the traditional SOAP-based services.
Context and Dependency Injection for Java EE Platform (CDI, JSR 299): This provides a built-in dependency injection mechanism for Java EE that offers a set of services that bind several components (for example, EJB and JSF Managed Beans) to lifecycle contexts. Another facility provided by CDI is a loosely coupled event mechanism that works with annotation and simple POJOs (Plain Old Java Object). In a nutshell, the main objective of CDI is to create a unified programming model for EJB and JSF while keeping other important services (transactions, for instance) available to all Java EE tiers.
Bean validation (JSR 303): Developers tend to validate objects in many layers. Sometimes they generate duplicated code and may even forget to replicate a validation logic to one of the layers, which can lead to catastrophic consequences. To solve such problems, the bean validation framework provides a standard set of validation rules that can be shared by all layers; so the same rule can be applied to the user interface (through JSF and managed beans) and more internal tiers (attached to JPA, for instance), avoiding duplicated code.
Enterprise JavaBeans 3.1: In this update of the EJB specification, the main focus was to make it simple and easy to use. The most noticeable change is that EJBs now can be packaged in WAR files, removing the need to produce specific packages for EJBs and combine them in an EAR file. But other important features were added, such as the following:
Singleton beans: These are the EJBs that can primarily be shared and support concurrent access, with the guarantee that the container will have only a single instance per JVM
Embeddable API for Java SE: With some limitations, it runs client code and EJB instances in the same JVM on SE environments using an embeddable container
EJB Lite: Since Java EE 6 has the concept of profiles, specific vendors can choose to implement the full container or the Lite version with a subset of EJB API
Servlet 3.0: Servlets are one of the main components of Java EE since its initial release, but few changes were made to its specification since then, except for adding filters and web application events. Servlet 3.0 adds important changes into the API such as the following:
Support for annotations: It's now possible to declare a servlet by just adding an annotation (
@WebServlet
) to a Java class. There are also annotation for filters, listeners, and parameters.Asynchronous processing: Servlets now allow asynchronous method calls. This feature helps applications to scale up, since it releases the caller while the processing is done by the server, allowing other requests to be accepted by the released thread.
Java Persistence API 2.0: JPA 2.0 has some major enhancements over the previous version. These new features include new annotations for mappings, enhancements to Java Persistence Query Language (JPQL), typed queries, shared cache, integration with bean validation, and probably the most powerful feature, Criteria API for dynamic strongly-typed query creation.
Java Server Faces 2.0: JSF 2.0 brings some important features long awaited by the community such as official integration with Facelets (an XML-based view declaration language), more options for error handling, better integration with Ajax, and many more. In this release, there is a new concept of resource and how you can integrate the different kinds (stylesheets, images, and JavaScript files). Componentization and composites form the main theme, with an easy API that supports the creation of UI components for reuse.
Note
Under the topic of Java EE 6, we could list and discuss several updates and enhancements in other areas, but that would be out of the scope of this book. We'll be showing examples on most of what we have seen here during the construction of case studies and the main application that will be built along with the book.