Java is one of the world’s most popular programming languages. This is a general-purpose, class-based, object-oriented language created with lesser implementation dependencies. It is preferred for development because it is fast, secure, and reliable. It also allows developers to write once and run everywhere” meaning, an application complied with Java is capable of on all platforms supporting Java without the need to recompile it.

Features of Java 17

This is the latest LTS version of Java. It has several features, among them are:

  • Context-specific deserialization filters
  • Strong encapsulation for JDK internals
  • Enhanced pseudo-random number generators
  • Deprecate the Applet API for Removal
  • Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
  • Remove the Experimental AOT and JIT Compiler
  • New rendering pipeline for macOS, using the Apple Metal API as an alternative to the existing pipeline that uses the deprecated OpenGL API
  • Removal of the Remote Method Invocation (RMI) Activation mechanism
  • Porting the JDK to MacOS/AArch64 in response to Apple’s plan to transition its Macintosh computers from x64 to AArch64

Features of Java 11

Java 11 released on 25th Sep 2018 has the following features:

  • Collection to an Arra
  • Improved Aarch64 Intrinsics
  • Nest-Based Access Control
  • Local-Variable Syntax for Lambda
  • The new HTTP client from the java.net.http package
  • The Not Predicate Method

There are 4 types of Java platforms, i.e:

  • Java Platform, Standard Edition (Java SE): offers the Java programming language’s core functionality
  • Java Platform, Enterprise Edition (Java EE): offers an API and runtime environment for developing and running highly scalable, multi-tiered, reliable, large-scale, and secure network applications
  • Java Programming Language Platform, Micro Edition (Java ME): It offers an API and a small-footprint virtual machine running Java programming language applications on small devices, like mobile phones.
  • Java FX: a platform for developing rich internet applications using a lightweight user-interface API

The following are the open souce implementations of Java,

  • OpenJDK: the open-source reference implementation version of the Java SE platform
  • Oracle JDK/JRE: production-ready Java implementation.

Install Java 11 on Rocky Linux 9 / AlmaLinux 9

Installing Java 11 on Rocky Linux 9 / AlmaLinux 9 can be done using two methods:

a. Install OpenJDK 11 from YUM repositories

OpenJDK 11 can be installed from the default YUM repositories using the command:

sudo yum install java-11-openjdk java-11-openjdk-devel

Dependency Tree:

Transaction Summary
================================================================================
Install  12 Packages

Total download size: 43 M
Installed size: 181 M
Is this ok [y/N]: y

Once complete, verify the installation;

$ java -version
openjdk version "11.0.17" 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS, mixed mode, sharing)

b. Install OracleJDK 11 on Rocky Linux 9 / AlmaLinux 9

You can also install the OracleJDK 11 on Rocky Linux 9 / AlmaLinux 9 using the below steps. First, install the required tools:

sudo dnf -y install wget curl

Now download OracleJDK 11 for your architecture from the official Oracle downloads page.

Once downloaded, install the package:

$ sudo rpm -Uvh jdk-11.*_linux-x64_bin.rpm
warning: jdk-11.0.17_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-11-2000:11.0.14-ga           ###########################

Once complete, check the version:

$ java -version
java version "11.0.17" 2022-01-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.17+8-LTS-263)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.17+8-LTS-263, mixed mode)

Install Java 17 on Rocky Linux 9 / AlmaLinux 9

Similar to Java 11, we will walk through how to install both the OpenJDK and Oracle JDK/JRE implementations.

a. Install OpenJDK from YUM repositories

OpenJDK 17 can also be installed from the YUM repositories. To get the available versions, use the command:

$ dnf search jdk | egrep -- '-17'
Last metadata expiration check: 0:07:36 ago on Sun 30 Oct 2022 11:54:33 AM CET.
java-17-openjdk.x86_64 : OpenJDK 17 Runtime Environment
java-17-openjdk-demo.x86_64 : OpenJDK 17 Demos
java-17-openjdk-devel.x86_64 : OpenJDK 17 Development Environment
java-17-openjdk-headless.x86_64 : OpenJDK 17 Headless Runtime Environment
java-17-openjdk-javadoc.x86_64 : OpenJDK 17 API documentation
java-17-openjdk-javadoc-zip.x86_64 : OpenJDK 17 API documentation compressed in a single archive
java-17-openjdk-jmods.x86_64 : JMods for OpenJDK 17
java-17-openjdk-src.x86_64 : OpenJDK 17 Source Bundle
java-17-openjdk-static-libs.x86_64 : OpenJDK 17 libraries for static linking

Now install OpenJDK 17 using the command:

sudo dnf install java-17-openjdk java-17-openjdk-devel

Dependency Tree:

Transaction Summary
================================================================================
Install  3 Packages

Total download size: 45 M
Installed size: 198 M
Is this ok [y/N]: y

Once complete, verify the installation:

$ java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.5.0.8-2.el9_0) (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.5.0.8-2.el9_0) (build 17.0.5+8-LTS, mixed mode, sharing)

b. Install OracleJDK 17 on Rocky Linux 9 / AlmaLinux 9

Install the required packages:

sudo dnf -y install wget curl

Now download the latest OracleJDK 17 version from the Oracle Java downloads. Download the required package for your architecture.

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

Install the package:

$ sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
warning: jdk-17_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-17-2000:17.0.5-ga            ################################# [100%]

Verify the installation:

$ java -version
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)

Set Default Java Version

There are situations when you have multiple Java version and you need to set the default version to use. For this scenario, begin by listing the available versions:

sudo alternatives --config java

If your system have multiple versions, you will see an output similar to this one:

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.17.0.8-2.el9_0.x86_64/bin/java)
   2           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el9_0.x86_64/bin/java)
*+ 3           /usr/java/jdk-17.0.5/bin/java

Enter to keep the current selection[+], or type selection number: 2

Select the preferred version as verify the selection:

$ java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.5.0.8-2.el9_0) (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.5.0.8-2.el9_0) (build 17.0.5+8-LTS, mixed mode, sharing)

Setting JAVA_HOME Environment

The JAVA_HOME Environment variable is usually used determine the install location and exact Java version to be used when running applications.

This setting can be made in the ~/.bash.rc file, but to make the settings persists, add them to /etc/profile as shown:

JAVA_HOME="/path/to/java/install"

For the changes made to take effect, source the profile:

source /etc/profile

Verify the made changes:

$ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el9_0.x86_64/bin

Test the Java Installation

To test if the installed Java is working as desired, we will create a simple Hello world application.

cat > Hello_World.java <<EOF
public class helloworld {
  public static void main(String[] args) {
    System.out.println("Hello Java World from Kenya! Java is amazing!");
  }
}
EOF

This application can be run using the default set Java version:

java Hello_World.java

Sample Output:

$ java Hello_World.java
Hello Java World from Kenya! Java is amazing!

It is also possible to run this application using a non-default Java version by providing the absolute path. For example:

##For Oracle Java17
$ /usr/java/jdk-*/bin/java Hello_World.java
Hello Java World from Kenya! Java is amazing!

Recommended books:

Verdict

That marks the end of this guide on how to install Java 17, Java 11 on Rocky Linux 9 / AlmaLinux 9. This knowledge will help you install any other preferred version, set and use the Java versions as desired.

Interested in more?

LEAVE A REPLY

Please enter your comment!
Please enter your name here