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.
What is Java used for?
Java is commonly used for the following:
- Developing Android applications
- Used for Server-Side Technologies like Apache, JBoss, GlassFish, etc.
- Programming of Hardware devices
- Used for Big Data Analytics
- Creating Enterprise Software
- Scientific Computing Applications
- Developing a wide range of Mobile Java Applications
History of Java Programming Language
Java has gone through a series of development phases to its current state and version. The major landmarks from the history of the Java language are:
- The original version of Java was called OAK. Initially, it was developed for handling portable devices and set-top boxes. Oak was a massive failure.
- In the year 1995, the name was changed from OAK to “Java” and was modified to take advantage of the burgeoning Web development business.
- In 2009, Sun Microsystems was acquired by Oracle Corporation and took charge of the 3 key Sun software assets: Java, MySQL, and Solaris.
The Java releases have been made in the following years:
Java Versions | Release Date |
JDK Alpha and Beta | 1995 |
JDK 1.0 | 23rd Jan 1996 |
JDK 1.1 | 19th Feb 1997 |
J2SE 1.2 | 8th Dec 1998 |
J2SE 1.3 | 8th May 2000 |
J2SE 1.4 | 6th Feb 2002 |
J2SE 5.0 | 30th Sep 2004 |
Java SE 6 | 11th Dec 2006 |
Java SE 7 | 28th July 2011 |
Java SE 8 | 18th Mar 2014 |
Java SE 9 | 21st Sep 2017 |
Java SE 10 | 20th Mar 2018 |
JAVA SE 11 | 25th Sep 2018 |
JAVA SE 12 | 19th Mar 2019 |
JAVA SE 13 | 17th Sep 2019 |
JAVA SE 14 | 17th Mar 2020 |
JAVA SE 15 | 15th Sep 2020 |
Java 16 | 16th March 2021 |
Java 17 | 14th September 2021 |
In this guide, we will walk through how to install Java 17, and Java 11 on Rocky Linux 9 / AlmaLinux 9. These Java versions have different features. These are:
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
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
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
In this guide, we will cover the installation of Java 17, and Java 11 on Rocky Linux 9 / AlmaLinux 9 using two implementations:
- OpenJDK: the open-source reference implementation version of the Java SE platform
- Oracle JDK/JRE: production-ready Java implementation.
1. 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)
2. 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 17 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)
3. 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)
4. 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
5. 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?
- Analyze Java code using Gradle in SonarQube and Jenkins
- Scan PHP|JavaScript|C#|HTML using Sonar Scanner and Jenkins
- Must-Read Books to Learn Java Programming