Java EE 8 brought forth some important changes, particularly focusing on modern Web application development. Although there are numerous major and minor changes in the overall Java EE platform, here we focus on a few notable ones in brief and not in any particular order.
1. JSON-P 1.1 Enhancements
JSON-P was introduced with Java EE 7. Java EE 8 enhanced it to align with the emerging standard. The key areas of improvements are:
- JSON Pointer: According to the IETF RFC 6901 standard, it is a pointer to a JSON document. This pointer references the document and has string-based syntaxes. This pointer may be used to transform a JSON document with add, remove, and replace operations. The JsonPointer instance may be created by using the Jsonb factory class and invoking the getValue() or replace() methods to transform the document.
- JSON Patch: According to IETF RFC 6902, the patch itself is also a JSON document that facilitates the transformation to the target JSON document. A sequence of operations may be applied to the target document: add, remove, replace, move, copy, and test. We can use the JsonPatchBuilder methods to construct the patch and then apply it to the target document using the JsonPatch apply() method.
- JSON Merge Patch: The IETF RFC 7386 standard provides guidance on how the patch is compared with the original documents and changes are made. If the element that the patch references is there in the original document, it transforms the value of the target; otherwise, it is freshly added. If it has a nullable value, that means the element will be removed.
- JSON Collectors: Added helper classes and methods to leverage Java SE 8 stream operations. We can use lambda to filter and collect a stream of values from JSON objects.
2. Introduction of JSON-B 1.0
JSON-B is a new API introduced with Java EE 8. It is but a natural augmentation of the JSON-P feature. JSON-B is a binding layer that serializes and deserializes Java objects to JSON messages and vice versa. It provides the algorithm behind the scenes to convert Java classes to JSON. Programmers can customize the mapping process with the help of annotation provided by the library, or the customization also may be done at runtime by the configuration builders. Prior to this built-in incorporation of JSON binding, there were other third-party JSON binding providers. Java EE 8, however, provides the flexibility to use them instead of its built-in support. The entry point of using this API is through the JsonBuilder class. This class provides support for selecting provider implementation, setting configuration properties, and so forth. The factory class Jsonb is an abstraction of JSON binding framework operations.
3. Servlet 4.0
Addressing the limitations of HTTP1.x is big issue, especially when using Servlet APIs. Therefore, the Servlet 4.0 API is enhanced with support for HTTP/2. The primary goal of HTTP/2 is to reduce latency and leverage parallel communication without resorting to multiple connections. Until HTTP 1.x, it was the only effective way to achieve some sort of parallelism. This was actually a workaround of a long awaited to be duly addressed problem with HTTP. HTTP/2 addressed this use, retaining the semantic of HTTP1.1. The changes are reflected in the introduction of the PushBuilder API introduced with Servlet 4.0. Read more.
5. JAX-RS 2.1 Enhancements
There are two key areas of JAX-RS that reflects its major changes: the reactive client APIs that leverage Java SE 8 and server-sent events. The reactive client APIs brought forth the flexibility it required which otherwise had to be done in a bit of a roundabout fashion with its prior versions. The long running connections with server-sent events can be reused for multiple events from the server. There are some minor improvements as well, such as support for JSON-B entity providers and HTTP patch requests.
6. Java EE Security API 1.0
The new Java EE Security API has a number of key improvements. The primary objective is to simplify the use of Java EE Security in their users’ approaches and underlying mechanism such as it can leverage in its implementation. New APIs were introduced, such as SecurityContext, HttpAuthenticationMechanism, and IdentityStore. The SecurityContext API enhanced the authentication process in the Web tier. To authenticate callers of a Web application, the HttpAuthenticationMechanism is designed to work on servlet containers only. The IdentityStore API is used to interact with user information store such as a database, and to authenticate or retrieve user group information.
7. Bean Validation 2.0 Enhancements
The bean validation API is modernized in different aspects. Some of them are the use of java.time APIs, repeatable annotation, and applying constraints to collection elements and optional wrappers. A bunch of new constraints were introduced: @Email, @NotEmpty, @NotBlank, @Positive, @Negative, @PositiveOrZero, @NegativeOrZero, @PastOrPresent, and @FutureOrPresent.
8. CDI 2.0 Enhancements
The specification is divided into three parts: Core CDI, CDI in Java SE, and CDI in Java EE. The bootstrap APIs enable bootstrapping a CDI container in Java SE environments. In the Java EE arena, the key improvements are in the observer ordering and the asynchronous event firing. There are other improvements, such as in the area of built-in annotation literals, alignment with Java SE 8 streams features, and lambda expression and SPI enhancements. Read more.
9. JSF 2.3 Enhancements
JSF 2.3 is enhanced by several fine-tuning aspects, such as better CDI, Web socket integration, leveraging bean validation, Ajax method calls, and new date/time support.
Apart from these, there are many other minor improvements. A few of the notable among of them are JPA 2.2, JavaMail 1.6, Common Annotation 1.3, Interceptors 1.2 rev A, and Web Socket 1.1. They are primarily maintenance releases. We’ll take each of major enhancements and go a bit deeper in subsequent articles.