Tuesday Jul 07, 2015

JPA and Java SE 8 Streams

Retrieving a large, i.e. a very large, dataset using JPA might be tricky as the whole result set has to fit within a java.util.List instance. So a very large data set might potentially hit the memory limits of the sever the application is running on.

For those scenarios with (very) large result set, pagination can be used to work-around that limitation.  See for example this "How To Stream/Serialize JPA Result As JAX-RS Response For Large Data" article.  But for those scenarios, the Java 8 Streams API would also be a good fit! Unfortunately, Streams are not supported in the current release of JPA (JPA 2.1 - JSR 338) as it predates Java SE 8. But this is clearly a potential RFE for the next update of JPA (see this specification RFE here). In addition, some of the JPA implementations have already started to add support for Java 8 Streams (e.g. Hibernate and EclipseLink).

We will have to wait a bit more to see what the scope of 'JPA.next' will be. What do you think? Would you like to see Java SE 8 Streams supported in 'JPA.Next'?

Tuesday Jun 30, 2015

Java 8 Free Online Course: Lambdas and Streams

It is probably fair to say that Java SE 8 is the most important Java release in the last decade… if not more! With the introduction of Lambda expression, Java SE 8 introduced a fundamentally new way of programming. The new Streams API lets process data in a declarative way while leveraging the underlying in more efficient way, etc.

During this summer, Oracle is conducting a Massive Open Online Course (MOOC) on Java 8 Lambdas and Stream. This free online course will start soon (July 14th). During this course, you will have a chance to learn how to :
  • Apply Lambdas to everyday problems
  • Convert anonymous classes to Lambda expressions
  • Apply the Streams API to solve problems of sorting, identifying the most and least, and reducing duplicates
  • Determine when to apply Lambdas (and when not to!)
  • Use Collectors
  • Improve performance with parallel streams
  • Debug Lambda expressions
Even though this is a 'core' Java SE course, it is also very relevant to Java EE developers as more and more Java EE 7 Application Server have been certified to run on top of Java SE 8. In addition, Java EE 8 will mandate Java SE 8 at minimum. So sooner or later... and rather sooner than later, you will use Java SE 8. Given that and if you haven't started yet to look closely at Java SE 8, this free MOOC is really an opportunity you can’t afford to miss. To enrol, just check this page.

Wednesday Oct 15, 2014

Java SE 8 (and Java EE 7) Comes to WebLogic!

As many of you know one of the key features of GlassFish 4.1 was support for Java SE 8. You may be glad to hear that WebLogic 12.1.3 now is also officially certified against Java SE 8. This makes WebLogic one of the earliest major commercially supported Java EE platforms to certify for Java SE 8. Keep in mind, WebLogic 12.1.3 also supports some key Java EE 7 APIs such as WebSocket, JSON-P, JAX-RS 2 and JPA 2.1 (read this excellent Aquarium entry by my colleague Bruno Borges for details).

This means that you can start using some of the very well received Java SE 8 features such as lambdas, streams and the new Date-Time API in Java EE 6 and Java EE 7 applications even in the most demanding 24 x 7 enterprise environments. WebLogic 12.1.3 has also taken advantage of new JDK 8 features such as improved garbage collection, security enhancements and JDBC 4.2.

You can read more details in a well written blog entry by Steve Felts of the WebLogic team.

Wednesday Aug 20, 2014

Using the Java SE 8 Date Time API with JPA 2.1

Most of you are hopefully aware of the new Date Time API included in Java SE 8. If you are not, you should check them out right now using the Java Tutorial Trail dedicated to the topic. It is a significantly leap forward in processing temporal data in Java. For those who already use Joda-Time the changes will look very familiar - very simplistically speaking the Java SE 8 feature is basically Joda-Time standardized.

Quite naturally you will likely want to use the new Date Time APIs in your JPA domain model to better represent temporal data. The problem is that JPA 2.1 will not support the new API out of the box. So what are you to do? Fortunately you can make use of fairly simple JPA 2.1 Type Converters to use the Date Time API in your JPA domain classes. Steven Gertiser shows you how to do it in an extremely well written blog entry. Besides explaining the problem and the solution the entry is actually very good for getting a better understanding of JPA 2.1 Type Converters as well. I think such a set of converters may be a good fit for Apache DeltaSpike as a Java EE 7 extension?

In case you are wondering about Java SE 8 support in the JPA specification itself, Nick Williams has already entered an excellent, well researched JIRA entry asking for such support in a future version of the JPA specification that's well worth looking at. Another possibility of course is for JPA providers to start supporting the Date Time API natively before anything is formalized in the specification. What do you think?

Thursday Mar 06, 2014

JavaScript in the Enterprise

Nashorn is the new JavaScript engine that will ship with Java SE 8 . Under the hood, it leverages the invokedynamic bytecode introduced in Java SE 7. By doing this, Nashorn offers improved performance. It also shine when it comes to compliance with the ECMA JavaScript specification. But that's not all, Nashorn also offers a nice interoperability between Java and JavaScript. For a good overview of Nashorn, see this recent 'Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM' article.

For Enterprise developers, Nashorn will offers new possibilities. For example, Avatar.js relies on Nashorn to support the Node.js programming model on the Java Virtual Machine. Project Avatar extends this model with added-value capabilities such as multiple event-loops with a built-in load-balancer; multithreading capabilities with a lightweight message passing mechanism; Model-Store, a pure JavaScript ORM based on JPA; etc.

Another way of leveraging Nashorn in the enterprise is scripting.  Instead of writing shell scripts, why not leverage JavaScript, eventually with some Java hooks if necessary? This simple script shows how to use Nashorn to monitor GlassFish via its REST Administration capabilities. This approach can easily be extended to fit any monitoring or management needs.