Skip to content

Java

Quite a lot of software is written using the Java programming language. Rather than this software being pre-compiled, self-contained, and ready to run, it instead needs a “Java Runtime Environment”. This provides the underlying libraries of code that the software needs at “run time”. This “Java Runtime Environment” is often abbreviated to just the JRE.

Java Versions Available

There are a few versions of this JRE installed on the HPC nodes. This will list the package names of the java packages installed:

$ dnf list installed | grep java
java-1.8.0-openjdk-headless.x86_64          1:1.8.0.372.b07-4
java-17-openjdk-headless.x86_64             1:17.0.7.0.7-3
java-latest-openjdk-headless.x86_64         1:20.0.1.0.9-8.rolling

These are the Java packages from OpenJDK which provides open-source implementations of Java. The headless just means there is no graphical user interface with this package.

A summary of the above is:

Package Name Description
java-1.8.0 Java version 1.8, also known as Java 8.0.
java-17 Java version 17.
java-latest Java version 20.   See below.

What’s the Latest Java Version Available?

Run the DNF package manager with the “info” option and the package name:

$ dnf info java-latest-openjdk-headless
Name         : java-latest-openjdk-headless
Version      : 20.0.1.0.9                       <== Version is here.
Release      : 8.rolling.el8
Summary      : OpenJDK 20 Headless Runtime Environment
URL          : http://openjdk.java.net/
Description  : The OpenJDK 20 runtime environment without audio and video support.

At this time it shows it is version 20. Note though that this is a “rolling” release. That means that it’s always the latest version available. At some point in time this will become version 21.

So currently java-latest provides java-20.

What’s the Default Java Version on the HPC?

Check it by running the Java command with the -version option. Note it’s just one dash only.

$ java -version
openjdk version "1.8.0_372"

This might change in the future.

How to Change your Java Version

You can set your default version to a later one. You might need to do this if you need to use a specific version of Java with your software. A good example of this is the genomics workflow software called “Nextflow”.

$ bin/nextflow -version
NOTE: Nextflow is not tested with Java 1.8.0_372 
It's recommended the use of version 11 up to 20
Error: A JNI error has occurred, please check your installation and try again.

The above error occurred because the default Java version on the HPC is 1.8 and Nextflow will not work with that version.

You can select a Java version that works by using the module program to set your JAVA_HOME and PATH environment variables. See Using Modules.

The command below will set these so that Java version 20 is your default java version:

$ module load java-20

Now Nextflow runs fine:

$ bin/nextflow -version

  N E X T F L O W
  version 23.04.2 build 5870
  created 08-06-2023 08:29 UTC (18:29 AEDT)
  http://nextflow.io

To return to your original settings unload the module:

$ module unload java-20

You can also do this within bash scripts like your PBS submission scripts. Note that in the example below I have placed the Nextflow program in my ~/bin directory so I use $HOME/bin/nextflow to provide the full path to the program.

#!/bin/bash

#PBS -l ncpus=1
#PBS -l mem=5GB
#PBS -l walltime=00:02:00

cd ${PBS_O_WORKDIR}
module load java-20
$HOME/bin/nextflow -version

That script can be submitted as a PBS job and, after it has run, the output will be the Nextflow title block and version.

Confused on Java Versioning?

Java versions before version 9 were numbered 1.6, 1.7, 1.8 and then they changed the version numbering scheme to be just 17, 18, 19, 20 etc. So Java 1.8 is actually version 8.0 !