SKP’s Java/Java EE Gotchas: Revisiting Java SE 9 Features, Part 1

Preparing for an interview? Want to just revisit Java SE 9 features? Trying to recollect or revise Java SE programming constructs? Let me take you back in time to what was introduced first in Java SE 9? Join me for this tutorial series on Java as we all eagerly await the official release of Java SE 14!

As I promised, I am back with the code samples of my earlier article Java SE 9... What's New? You may refer the earlier article to understand the newly introduced features at a high level. This article provides the code samples for each of the features.

You may download the code samples for the following new features here. (Import as eclipse project, set compiler/environment as Java 9. Run the main class 'Java9Application' to see the output/outcome of the Code Samples.)

I plan to start by re-visiting a Java 8 feature, Default Interface Methods.

Acceptance Testing Using Arquillian (Jakarta EE)

In agile projects using Java/JEE, the focus and scope of developer testing are usually diminished to either unit testing or very basic functional testing. Arquillian brings in a newer thought process of integration and acceptance testing that includes Continuous Integration and testing within the JEE container, especially for JEE products or solutions that require functionalities to be tested across various containers. This provides the most productive way. According to the internet, Arquillian was also the "Duke's Choice Award for Developer Productivity at JavaOne Conference 2011." In my experience, it not only enhances the productivity of developers but also promotes good practices. 

It allows you to convert your TestNG or JUnit (among others) test cases into Arquillian test cases with few changes. Also, it allows you to directly use CDI in your test code. This allows you to inject dependencies such as EJB or web services directly in your test cases. The central thought process involved in using Arquillian is the ShrinkWrap API provided by it. It allows you to package your product or project code into Archives like JAR, WAR, and EAR. Along with the project code that is to be tested, the test cases are also packaged. It then allows multiple Maven configurations to allow direct deployment into one of these modes (that we used for our product).

Starting With Apache Maven

Apache Maven is a build or a total project management tool that scores over its predecessors such as ANT for Java builds with the following advantages:

  • Useful when multiple JAR files are required for builds
  • Resolving recursive dependencies during build time
  • Creating project structures that are standardized
  • Building, publishing, and deployment of applications
  • Supports lifecycle of an application along with plugins

I have created an alumni project that is a dynamic web archive with a Servlet that says “Hello, Alumni”. 

Contexts and Dependency Injection (CDI): Eager Extensions

CDI does not provide eager extensions out of the box. Even though there is @ApplicationScoped, which is intended to work in a similar way to eager instantiation, it does not behave in the specified fashion. 

I am going to describe how to use CDI extensions to get eagerly instantiated beans following the CDI lifecycle — inside the container. I have used this in Wildfly 8.0. 

Revisiting Java SE 5 Features! [SKP’s Java/Java EE Gotchas]

So, preparing for an interview? Want to revisit some Java SE 5 features? Trying to recall or revise a Java SE programming construct? Let me take you back in time to what was introduced first in Java SE 5! This progression and tutorial series on Java, as we all eagerly await the official release of Java SE 9!

Java SE 5 Release Date: 04-10-2004