Tuesday, December 24, 2013

Book Review: Java EE 7 First Look

Java EE 7 was formally released earlier this year. NDJOBO Armel Fabrice's book Java EE 7 First Look advertises that the reader of this Packt Publishing book can "discover the new features of Java EE 7 and learn to put them together to build a large-scale application." I review the PDF version of this book in this post.

Preface on Book Objective, Intended Audience, and Prerequisites

The Preface of Java EE 7 First Look outlines the objective of the book: "This book does not aim to show how to implement the different aspects of each Java EE 7 specification or list the best practices. Rather, ... this book will help you discover the innovations introduced by Java EE 7 and gives you ideas to build solid applications.

The Preface lists four things software products necessary "to implement the various examples present in this book": NetBeans IDE 7.3.1+, JDK 7, GlassFish 4 b89+, and MySQL 5.5+. Although all of these are used in the book, only a fraction of the examples directly use NetBeans, GlassFish, and MySQL in approaches specific or exclusive to those tools. Many of the examples could be run without those specific tools with few and minor adjustments.

According to the Preface, the book is targeted primarily at three types of individuals: Java EE beginners, experienced Java EE developers wanting to learn the new Java EE 7 features, and architects wanting to learn how to put the covered technologies together to build "robust and secure enterprise applications." For reasons that I state at the end of this post, my opinion is that this book is best suited for the second group (experienced Java EE developers wanting to learn the new Java EE 7 features).

Chapter 1: What's New in Java EE 7

Chapter 1 of Java EE 7 First Look begins with a history of Java EE. The chapter discusses the revised "main goals of Java EE 7" and then looks briefly at how Java EE 7 improves productivity and HTML5 support. The chapter concludes with a section on "Novelties of Java EE 7" in which JSR 342 is discussed. This coverage states that there are 4 new specifications (Concurrency Utilities for Java EE, Batch Applications for the Java Platform, Java API for JSON Processing, and Java API for WebSocket) and talks about some of the most significantly updated specifications including Java Servlet 3.1, Expression Language 3.0, JavaServer Faces 2.2, Java Persistence API 2.1, Enterprise JavaBeans 3.2, Java Message Service 2.0, Java API for RESTful Web Services 2.0, Contexts and Dependency Injection for Java EE 1.1, and Bean Validation 1.1.

Chapter 2: New Specifications

The second chapter of Java EE 7 First Look looks at the four new specifications highlighted in the first chapter (Concurrency Utilities for Java EE, Batch Applications for the Java Platform, Java API for JSON Processing, and Java API for WebSocket) in more detail.

The chapter provides a summary of how important concurrency has become in modern software development and why Java EE containers formally did not support concurrency. It then looks at the most important interfaces supporting concurrency in Java EE applications.

Chapter 2 begins coverage of the Batch API for the Java Platform by defining batch processing and explaining how batch processing can help performance and handling of exceptions. Examples are provided of employing batch processing in Java EE with use of batch.xml, Batchlet, JobOperator, chunk, and step.

The second chapter's coverage of Java API for JSON Processing begins with a brief introduction to JSON, which it describes as "a lightweight data-interchange text format" that is "based on a subset of JavaScript, but is completely language independent." I liked the section in this chapter that compared XML to JSON and provided a fairer representation of their respective advantages and disadvantages than one often sees in modern software development literature.

The JSON Processing coverage continues with more detailed looks at the JSON streaming API (javax.json.stream package) and the JSON object model API (javax.json package). I liked this section's explanations of their differences and likening them to XML analogs for stream and DOM manipulation.

New Java support for WebSocket is the final topic of Chapter 2 and this section starts with a definition of WebSocket and an explanation of why WebSocket is useful.

Chapter 3: The Presentation Layer

Java EE 7 First Look's third chapter talks about "improvements in the Java EE platform for the presentation layer" with specific focus on updated specifications of Servlet 3.1, Expression Language 3.0, and JavaServer Faces 2.2. After a brief history of servlets and example of a Java servlet, the author focuses on two improvements in Servlets from 3.0 to 3.1: non-blocking I/O API (javax.servlet.ReadListener and javax.servlet.WriteListener as well as ServletInputStream and ServletOutputStream) and protocol upgrade processing (HttpServletRequest.upgrade(Class), javax.servlet.http.HttpUpgradeHandler, and javax.servlet.http.WebConnection).

The section of Chapter 3 on Expression Language starts with a very brief introduction describing what Expression Language is and demonstrating it in a brief JSF code snippet. Expression Language coverage then moves to 3.0 improvements with details laid out for use of Expression Language in Java SE environments (javax.el.ELProcessor), lambda expressions, collection objects, new operators (string concatenation, assignment, and semicolon), and static fields/methods.

Chapter 3's JSF coverage begins by describing JSF as "a component-based architecture with a set of standard UI widgets and helper tags." Following the same pattern as the chapter's Expression Language coverage, the JSF coverage shows a JSF code listing before going into what's new in JSF 2.2. New JSF 2.2 features covered in this chapter include HTML5 support (pass-through attributes and pass-through elements), Resource Contract Libraries, Faces Flows, and Stateless Views.

Chapter 4: The Java Persistence API

Chapter 4 of Java EE 7 First Look covers Java Persistence API 2.1 and Java Transaction API 1.2. As was done in Chapter 3, Chapter 4 provides an overview of JPA, what it is, and how to use it, before moving onto new features of JPA 2.1. The covered new features are persistence context synchronization, CDI support, new annotations (@Index and @ForeignKey), Entity Graphs, Java Persistence Query Language improvements, Criteria API improvements, and DDL generation standardization and improvements.

Chapter 4 moves from coverage of new JPA 2.1 features to new JTA 1.2 features. This section follows the pattern established in this and earlier chapters of first explaining the overall technology and showing a code listing example of the concept before moving onto new features. New JTA 1.2 features covered in this chapter are two new annotations (javax.transaction.Transactional and javax.transaction.TransactionScoped) and a single new exception (javax.transaction.TransactionalException). The new JTA 1.2 features are covered with significantly less detail than provided for the new JPA features.

Chapter 5: The Business Layer

The fifth chapter of Java EE 7 First Look covers EJB 3.2 and "putting all Java EE 7 specifications together." The chapter describes the "business layer of an application" between the database and presentation layers and how EJB is part of that business layer. The chapter talks about features of EJB that are made optional in Java EE 7 and are now covered in a separate EJB 3.2 Optional Features for Evaluation document. The author states that EJB 3.2 only adds minor enhancements to EJB and then briefly outlines enhancements to stateful sessions beans and provides code examples and descriptions of each.

Improvements in EJB 3.2 for EJB Lite (introduced in EJB 3.1 [Java EE 6]) are covered next. Text and code examples are used to describe these EJB Lite enhancements as well.

Chapter 5 moves to a brief introduction to Java Message Service (JMS) and Message-Driven Beans (MDB). Brief coverage of how EJB 3.2 has been adjusted to conform to JMS 2.0 follows. The author points out that EJBContainer, first introduced with EJB 3.1, now implements the AutoCloseable interface, meaning that it can participate in the try-with-resources mechanism introduced with Java SE 7.

The remainder of Chapter 5 is on "putting it altogether." This section includes several UML diagrams and design artifacts and, without any code, discusses requirements of the sample project.

Chapter 6: Communicating with External Systems

Chapter 6 of Java EE 7 First Look describes changes to four APIs related to "system integration problems": JavaMail, Java EE Connector Architecture, Java Message Service, and JAX-RS. As has been done in the coverage of most of the other Java EE topics in this book, these are each introduced in general and then Java EE 7 enhancements for each are explained.

Enhancements to JavaMail 1.5 are discussed. These enhancements include two new annotations (@MailSessionDefinition and @MailSessionDefinitions) targeted at the application server environment, new "shortcut" methods, and changes to field modifiers.

Coverage of changes to Java EE Connector Architecture 1.7 (JSR 322) spends far more time describing what JCA is and hot it is used than in discussing enhancements to JCA 1.7 (one paragraph, three bullets, no code). Covered new JCA features include the new annotations @ConnectionFactoryDefinition and AdministeredObjectDefinition.

Chapter 6's JMS coverage does not spend much time covering what JMS is, presumably because this was covered to some degree in Chapter 5 on JMS and MJBs. Features new to JMS 2.0 are covered more extensively and include greater API simplicity and delivery delay and sending messages asynchronously.

Java API for RESTful Web Services 2.0 is the final major topic of Chapter 6. This section begins by considering web services and when to use them generally, but then explicitly states that the book focuses only on REST-based web services. I've been excited about JAX-RS 2.0 (see my review of related book ) and was glad to see several new features of JAX-RS 2.0 covered in this section: Client API, asynchronous processing, and filters and entity interceptors.

Chapter 7: Annotations and CDI

Java EE 7 First Look's seventh chapter begins with a review of JSR 250 (Common Annotations) followed by a description of how to write one's own custom annotation. The discussion on writing a custom annotation also illustrates the need in Java SE 6 to implement the javax.annotation.processing.Processor interface (see also my article Better JPA, Better JAXB, and Better Annotations Processing with Java SE 6 for further details). The section on annotations concludes with the introduction of javax.annotation.Priority.

Context Dependency Injection (CDI) is covered next. Like the annotations and most other concepts in this book, it is introduced generally first before coverage of new features begins. Quite a few code examples demonstrate how to use CDI in a variety of different situations. The coverage of new CDI 1.1 features includes @Vetoed, use of CDI.current() to "access the current CDI container programatically," and use of AlterableContext "to allow explicit destruction of bean instances in applications."

Chapter 8: Validators and Interceptors

The Java EE 7 specifications focused on in Chapter 8 are Bean Validation 1.1 (JSR 349) and Interceptors 1.2 (JSR 318). The chapter's coverage of Bean Validation begins with a table of built-in constraints, followed by examples and discussion of applying constraints. The section includes with coverage of implementing custom constraints. After devoting quite a few pages to illustration of and examples of using Validation, the section begins coverage of new Java EE 7 features of Validation including open sourcing of Bean Validation implementation, CDI/dependency injection integration and the ability to validate parameters of methods and constructors and return types on methods.

Like the section on Validation, the section on Interceptors begins by providing a background of what Interceptors are and how to use them. The new Interceptor 1.2 features covered in this section include intercept constructor invocation, interceptor binding, and defining interceptor order.

Chapter 9: Security

The ninth and final chapter of Java EE 7 First Look is on security. The chapter introduces Java Authentication SPI for Containers (JASPIC) [JSR 196]. The author describes the JASPIC specification as "a set of standard interfaces for the development of modules for authentication, which allow secure access to web resources (Servlets, JSP, and so on), among others." There are numerous pages of code listings, illustrative text, and screen snapshots devoted to covering implementing JASPIC with GlassFish. The chapter then moves onto new features introduced with "Maintenance Release B of JASPIC Specification." New features covered include increased level of standardization of how authentication is handled across different servers and how the application context provider is identified and support for forward and include mechanisms.

General Observations
  • Nearly every introduced Java EE 7 new feature covered in this book was covered only after an overall description of the specification including its history and general usage before the new features were available.
    • The brief review of a specification's history and illustration of using that specification provides a nice review before jumping into what's new in Java EE 7 about that specification.
    • Although this review of existing specifications provides is helpful for those who have used Java EE to some degree before, I doubt these reviews would be sufficient background for someone entirely new to Java EE.
    • A true Java EE beginner would probably be better off learning Java EE in a fashion that integrates all versions of Java EE rather than focusing primarily on the latest version of Java EE (such as via the Java EE 7 Tutorial).
  • Java EE 7 First Look is generally well-written and I only found a few typos, most of which were extremely minor. The most obvious were a couple cases where Java class or interface names had their first letter in lowercase even though that class or interface actually follows the Java convention of beginning with a capital letter.
  • Java EE 7 First Look seems particularly well suited for someone who has used Java EE before, but has little or no exposure to Java EE 7.
  • Java EE 7 First Look is about 165 pages of prose when one doesn't count the index and advertisements for related Packt Publishing books. The nine chapters don't have a lot of extra fluff and remain focused on covering Java EE 7 features, how they improve existing Java EE support, and how they can be used together.

Java EE 7 First Look provides convenient access to the features of Java EE 7 that will help Java EE developers be more productive and accomplish more for their clients. Although most of these features are described in detail in blogs, articles, and in the Java EE 7 Tutorial, Java EE 7 First Look collects all of them in one place and keeps its focus on the new features with only brief references to historical information and previous Java EE versions. Java EE 7 First Look provides an overall view of the collective benefit of Java EE 7 new features with some attention paid to implementing these features individually and with one another.

Anyone interested in the e-book version of Java EE 7 First Look might want to take advantage of the Packt Publishing Ebook Bonanza that runs through 3 January 2014, offering the electronic version of this book for $5 (USD).

No comments: