18 november 2009

Devoxx 2009 - Day 2: Java EE 6 platform

After 2 subsequent years of getting the same information on Java EE6, it was about time to get some real information on the evolution of Java EE. And with a different speaker than the past 2 years it was more likely to get a different story. After all, Roberto Chinnici wasn't the most interesting speaker to me (and he's doing a keynote on JEE 6 :-?).

But as the 2 speakers said in the beginning, JEE 6 was very close to being delivered (which means that all the reference implementations of the specs have been developed as well), so we were definitely about to get something new here...

And sure we did! The presentation was a mix of slides and demo's with real code for each topic of the presentation:

  • JPA 2.0
  • servlet 3.0
  • EJB 3.1
  • JSF 2.0
  • bean validation 1.0
  • JAX-RS 1.1

The entire demo is based on Glassfish, which is the platform on which all the reference implementations were built. Glassfish has modularity built in via OSGi, but it is encapsulated into HK2, to make it more extensible. Yes, former Sun was never keen on OSGi, but there was no escaping since so many main players in the Java community use OSGi (with IM in the first place, but also SpringSource).

Configuration in Java EE is more and more optional. All the specs make extensive use of annotations, with better default values. Hope they keep it to a usable level (and avoid annotation hell...).

The Java EE spec as a whole is around since 2001 (starting with J2EE 1.2, built upon the concepts of Java 2).  Back then there were about 10 specs; the newest JEE 6 counts 27 different specs.  Some concepts will be pruned (marked obsolete, might disappear in JEE7): CMP entity beans (replaced by JPA), JAX-RPC (replaced by JAX-WS), JAX-R (XML-registries) and JSR-88 (application deployment).

The major change in the Java EE specification is that a software vendor no longer needs to implement the full specification to be Java EE compliant. The spec allows the definition of profiles for specific (development) domains. The first profile that is defined, is the web profile. This profile is a subset of the full Java EE specification. To be JEE Web Profile compliant, you need to implement the following specs:

  • jsf
  • servlet
  • jsp
  • el
  • jstl
  • ejb lite
  • managed beans
  • interceptors
  • jta
  • jpa
  • bean validation
  • jcdi
  • @inject

This means the e.g. Tomcat can be extended to meet the web profile specs to be JEE 6 compliant. Apart from the typical web specifications, the EJB Lite spec should be implemented. This means the following:

  • local session beans
  • injection
  • cmt/bmt
  • interceptors
  • security

These EJB-related specs are not required in the web profile:

  • message driven beans,
  • rmi/iiop
  • remote interface

Managed beans

New in the Java EE spec is the concept of managed beans. These are container managed POJO's, with support for life cycle management, injection of resources and interceptors. It is a lightweight component model. Sounds familiar. I think I heard something like this about 4 years ago. It was called "Spring" or something... :-) Anyway, the concept of managed beans is re-used for EJB's (= a managed bean with transaction support, security and remotely invocable).

Lifecycle management can be achieved by specifying PostConstruct and PreDestroy annotations to certain methods. There is no more need for a formal constructor; let the beans be created by the container and add lifecycle method to invoke you own logic.

Java Persistence API (JPA)

JPA: evolves separately from EJB spec now. New features:
richer mapping

Querying: JPQL
non-polymorphic querying
joins in subqueries
extra keywords for new functions like ABS, etc.
new locking methods, not only optimistic, also pessimistic, lock, lock and read, read then lock
criteria-API: type safe way for querying data
caching added in persistence
not in the JEE spec, but added cache API because all JEE platform vendors have a second level cache. Annotation @cacheable and api methods to check if data is in the cache.

Servlet API

In the servlet API the remarkable thing is that the web.xml becomes optional/obsolete. Annotations take over the role of configuration: @webservlet.

Pluggability of third-party servlets and web frameworks is improved by providing web-fragment XML-files.

Other new stuff in the servlet API:

  • static resources
  • config api
  • file upload
  • servlet security annotation


EJB 3.1

The EJB specification is extended with interceptors, the AOP-way (like - again - in SpringAOP). This means that you can easily plug-in security, logging or performance measuring components.

Local & remote interfaces become optional (only the bean itself with annotations and default all methods are public and locally invocable). Just specify @EJB and you automatically assume a stateless session bean with local invocation and all the (public) methods can be reached.

Asynchronous invocation has been added to EJB's. This means that you don't have to apply JMS for asynchronous calls. JMS is meant for asynchronous message delivery, not method invocation. With asynchronous invocation you can do a fire and forget of a method (if you're not expecting a result of the invocation, off course). Don't start spawning your own threads, because they are not managed by the container!

The timer service has be modified with a cron-likke syntax. The entire principle of the timer got its inspiration from crontab. This can simply be done by adding a @schedule annotation (with the right parameters) to a method of your stateless session bean.

And finally, on the EJB 3.1 spec, there is the singleton bean. By specifying the @singleton annotation to your bean class, you can be absolutely sure that there will be exactly 1 instance of your bean class present in your container. This can e.g. be useful for caching.

Java Server Faces (JSF)

I've never quite understood much of Java Server Faces... And the same goes for the novelties introduced in this new spec... Anyway, I try to recap the key features in the new spec. The new JSF spec can be run indepently of the latest servlet spec. It can runb on Servlet 2.5 but then it requires a web.xml config file (won't work with tghe typical @nnotations).

JSF has always been a rather healthy concept for the component market (re-usable web components) and had good IDE support. But writing your own components was pretty hard. This has been improved in JSF 2.0.

New is also the support for AJAX in JSF. THis can be done in 2 different ways: either via javascript or via a specific AJAX-tag.

Other new stuff in JSF:

  • bookmarkable urls
  • templating
  • project stages (dev/test/prod)

The reference implementation of the new JSF spec is available in Mojarra. It can be used in any runtime (could be tomcat or whatever server).

Bean validation

The bean validation is a new spec in the Java EE platform. It offers a mechanism for validations (hence the name :-)), in a constrain once, validate anywhere way. Validations can be added to properties via annotations and these can be checked on all parts of the application: frontend, mid-tier and backend. A standard number of validation rules are available: not null, length check, range check, ... But you can easily add your own custom validations.

JAX-RS 1.1

The JAX-RS spec is available since mid 2008, but it has has some (minor) changes to fully integrate with Java EE6 (and EJB in particular). As far as REST-support is concerned, there wasn't much new here compared to the talk I attended last year.

This was a very interesting talk. It finally showed something tangible compared to the talks of the JEE6 spec lead the last  years... Besides, at this very moment, he (Roberto Chinnici) is doing a key note on JEE 6. Again: nothing new here (espacially not after I attended this JEE 6 university session).

10:45 Gepost door There's more to life than what you see through windows in Javapolis | Permalink | Commentaren (0) | Tags: devoxx09, java ee 6 |  Facebook |

De commentaren zijn gesloten.