JEE 6 NEW FEATURES
Web profile :- Java EE 6 defines the first profile, called the Web Profile. This initial profile is a Java EE platform subset for web application development.
- JavaServer Faces (JSF) 2.0
- JavaServer Pages 2.2 and Expression Language (EL) 1.2
- A Standard Tag Library for JavaServer Pages 1.2
- Debugging Support for Other Languages 1.0
- Contexts and Dependency Injection for the Java EE Platform 1.0
- Dependency Injection for Java
- Enterprise JavaBeans 3.1(EJB Lite)
- Java Persistence API 2.0
- Common Annotations for the Java Platform 1.1
- Java Transaction API (JTA) 1.1
- Bean Validation 1.0
- Java API for RESTful Web Services (JAX-RS)
- Contexts and Dependency Injection for the Java EE Platform (CDI) -- CDI unifies and simplifies the EJB and JSF programming models. It allows enterprise beans to act as JSF managed beans in a JSF application, and brings transactional support to the web tier. CDI builds on managed beans, which are designed to unify all of the various types of beans in Java EE 6. In JSF2.2 backing beans are now managed beans & denoted by annotation @ManagedBean, CDI services allow Java EE components, including EJB components, to be bound to lifecycle events using @Model.
@Inject, identifies a point at which a dependency on a Java class or interface can be injected. @Interceptors allows interceptors in managed bean @Inject. Identifies injectable constructors, methods, and fields.@Qualifier. Identifies qualifier annotations. Qualifiers are strongly-typed keys that help distinguish different uses of objects of the same type. For example, a@Red Carand a@Blue Carare understood to be different instances of the same type. In this example,@Redand@Blueare qualifiers.@Scope. Identifies scope annotations.@Singleton. Identifies a type that the injector only instantiates once@Named. AString-based qualifier to access methos in Facelets using EL.- Bean Validation :- Bean Validation affords a standard framework for validation, in which the same set of validations can be shared by all the layers of an application. Bean Validation includes a number of built-in constraint definitions. You add your own constraints by declaring an annotation type that specifies a validator class.
- e.g. @ZipCode, @Size, @ConstraintValidator, @NotNull
- Servlet 3.0 :- Web fragments enable web frameworks to self-register, eliminating the need for you to register them through deployment descriptors. The
element identifies a web fragment. A web fragment must be in a file namedweb-fragment.xmland can be placed in any location in a web application's classpath. However, it's expected that a web framework will typically place its web fragments in theMETA-INFdirectory of the framework's JAR file. - Instead of creating deployment descriptors, you can annotate classes to specify servlet-related deployment information.
- @WebServlet
- @WebFilter
- @WebInitParam
- @WebListener
@MultipartConfig- Asynchronous Processing in Servlet 3.0 :- A servlet no longer has to wait for a response from a resource such as a database before its thread can continue processing. To make a servlet asynchronous, you specify
asyncSupported=truein a@WebServletannotation - Simplified Page Authoring in JSF 2.0 :-
- Facelets :- In JSP, elements in a web page are processed and rendered in a progressive order. 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 enables code reuse through templating and can significantly reduce the time to develop and deploy UIs.
- Templating
- Composite Components
- Support for Ajax in JSF 2.0 :-
tag can invoke functions in the JavaScript API. - Programatically servlet & filter can be added at runtime.
- JSF2.0 :- All resources like css, js, images, properties file will go under resources folder.
- EJB 3.1 :-
- No-interface view. Allows you to specify an enterprise bean using only a bean class without having to write a separate business interface. Local interface is optional.
- Singletons. Lets you easily share state between multiple instances of an enterprise bean component or between multiple enterprise bean components in an application.
- Asynchronous session bean invocation. Enables you to invoke session bean methods asynchronously by specifying an annotation @Asynchronous. @Startup annotation guarantees that @PostConstruct method will be called on application initialization.
- Simplified Packaging. Removes the restriction that enterprise bean classes must be packaged in an
ejb-jarfile. You can now place EJB classes directly in a WAR file. - EJB Lite. Is a subset of EJB 3.1 for inclusion in a variety of Java EE profiles.
- Timer :- Programmatic & calendar based scheduling. Cron like syntax.
- JPA Enhancements:-
- In JPA 2.0, you can map collections of basic data types, such as
Strings orIntegers, as well as collections of embeddable objects. - In query, case statement, nullif, coalesce are supported.
- Criteria API supports builder pattern to generate queries.
- Misc Features :-
- Portable JNDI Name
- Bean has a
@LocalBeanannotation -> bean has a no-interface view - Bean has a
@Localannotation -> bean has a local view - Bean has a
@Remoteannotation -> bean has a remote view
The following table depicts what type of managed classes can inject what objects.
| Resources | Stateless | Stateful | MDB | Interceptors |
|---|---|---|---|---|
| JDBC DataSource | Yes | Yes | Yes | Yes |
| JMS Destinations, Connection Factories | Yes | Yes | Yes | Yes |
| Mail Resources | Yes | Yes | Yes | Yes |
| UserTransaction | Yes | Yes | Yes | Yes |
| Environment Entries | Yes | Yes | Yes | Yes |
| EJBContext | Yes | Yes | Yes | No |
| Timer Service | Yes | No | Yes | No |
| Web Service reference | Yes | Yes | Yes | Yes |
| EntityManager, EntityManagerFactory | Yes | Yes | Yes | Yes |
Java EE 5 introduced several metadata annotations as part of JSR 250. Although primarily geared toward EJB, these annotations also apply to Java EE components such as Servlets, JSF managed beans, and application clients.
The following annotations can be used in a field or a setter method for dependency injection. However, these annotations may also be applied at the class level for defining dependencies and then used with JNDI look up.
| Annotations | Usage | Components that can use |
|---|---|---|
| javax.annotation.Resource | Dependency injection of resources such as DataSource, and JMS objects | EJB, Web, Application Client |
| javax.ejb.EJB | Dependency injection of Session beans | EJB, Web, Application Client |
| javax.xml.ws.WebServiceRef | Dependency injection of Web services | EJB, Web, Application Client |
| javax.persistence.PersistenceContext | Dependency injection of container-managed EntityManager | EJB, Web |
| javax.persistence.PersistenceUnit | Dependency injection of EntityManagerFactory | EJB, Web |
JEE 7 New Features
- CDI 1.1 (JSR 346) :- Can specify package as @Vetoed & classes are retrieved using auto discovery.
- Bean Validation 1.1 (JSR 349) :- Pre/Post conditions on constructor, methods.
- Interceptors 1.2 (JSR 318) :- Interceptor associated with constructor. @AroundConstruct
- @Priority - priorirty can be set for different interceptors
- Concurrency utilities 1.0 (JSR 236) :- Before JEE7, creating threads were discouraged in EE container. Thread pool of EJBs were managed by container.
- User threads in Java EE applications
- The ability to support simple and advance concurrency design patterns
- And to extend Concurrency Utilities API from Java SE (JSR 166y)
- New classes ManagedExecutor, ManagedScheduledExecutor, ManagedThreadFactory, DynamicProxy
- reates dynamic proxy objects, and adds contextual information available for applications running in Java EE environment
- It supports Classloading, JNDI, Security,
- JPA 2.1 (JSR 338) :-
- Schema generation
- @Index - define index in JPA mapping. In schema generation index will be created.
- Calling stored procedure in JPA
- JTA 1.2 (JSR 907) :-
- @Transactional - Transaction management on Managed Beans as CDI interceptor binding
- EJB 3.2 (JSR 345) :-
- Disable passivation of stateful ejb
- Async + non persistent timer
- JMS 2.0 (JSR 343)
- Simplified API to consume & produce messages.
- Autoclosable implemented.
- Annotation to create JMS factory connection definition, JMS destination definition.
- Servlet 3.1 (JSR 340)
- Servlet non blocking I/O - Only for asynchronous servlet. New interface ReadListener, Writelistener.
- New methods like setReadListener, isReady, isfinished in ServletInputStream interface,
- New methods like setWriteListener, canWrite in ServletOutputStream interface.
- Improved security. Now can deny http type request by configuring in web.xml file.
- Web Socket 1.0 (JSR 356)
- Annotated server endpoint - enables full duplex bi-directional communication over single TCP connection.
- LifeCycle callback methods - onOpen, ocClose, on Error
- Annotated client endpoint
- Websocket encoder & decoder
- Expression Language 3.0 (JSR 341)
- ELProcessor - Evaluate EL expression, GET/SET bean properties,
- JSF 2.2 (JSR 344)
- FlowFaces, FileUpload component,
- JAX-RS 2.0 (JSR 339)
- New API to consume services
- Async client - Async invocation, Async server - Async processing
- Message Filter - Used to process Incoming/Outgoing request response headers
- Entity interceptors- Marshalling/Un-Marshalling of HTTP message bodies.
- JSON-P 1.0 (JSR 353)
- JSON builder
- JSON parser
- Batch 1.0 (JSR 352)
- Chunk style processing, BatchLet style processing, Step processing, batch partition
- Creating batch workflows
- JavaMail 1.5 (JSR 919)
- JCA 1.7 (JSR 322)
- Java Connector Architecture
- Default Resources
- Default JMSConnectionFactory
- Default concurrency objects - DefaultMangedExecutorService, DefaultMangedScheduledExecutorService, DefaultMangedThreadFactory, DefaultContextService