Java is a popular programming language initially created by James Gosling at Sun Microsystems but is now owned by Oracle Corporation. The first release of Java was in 1995. Java was designed to be platform-independent, meaning any program coded in Java can run on any system that has a Java Virtual Machine (JVM) installed and working. Java is also an object-oriented programming (OOP) language and it provides features such as classes, objects, inheritance, and polymorphism, allowing developers to build modular and reusable code.

For you to develop Java applications, you need to install the JDK, which includes the Java compiler (javac), the Java Virtual Machine (JVM), and other tools for development and debugging. Alternative is Java SE which is a basic version of Java, providing core functionality for developing desktop, web, and command-line applications. It includes libraries for networking, file I/O, GUI (Graphical User Interface), and more.

In this article we shall cover the installation of Java 17 (OpenJDK 17) on CentOS 7 / RHEL 7 Linux system. Plenty of community libraries and frameworks are available to accelerate Java development, such as Spring Framework, Apache Maven, Hibernate, and many more.

Install Java 17 (OpenJDK 17) on CentOS 7 / RHEL 7

Java remains a popular choice for developing various software systems and with a large community of support it makes it a powerful programming language for developers. If you need to begin developing applications with Java 17 on CentOS 7 / RHEL 7 system, then this article is for you.

Java 17 is most recent long-term support (LTS) release of the Java programming language. This release introduced several new features, enhancements, and bug fixes. Consult official release notes and documentation for the specifics on new features and improvements available in Java 17.

Step 1: Update system

Update your system

sudo yum -y update

Install wget command line tool that will be used to download Java 17 binary.

sudo yum -y install wget vim

Step 2: Download Java 17 binary

You can get the latest Oracle JDK 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

In this example we’ve downloaded the version for Intel 64-bit CPU architecture.

Step 3: Install Java 17 on CentOS 7 / RHEL 7

Use yum or rpm commands to install the package.

sudo yum -y install ./jdk-17_linux-x64_bin.rpm

Expected installation output:

Examining ./jdk-17_linux-x64_bin.rpm: 2000:jdk-17-17.0.7-8.x86_64
Marking ./jdk-17_linux-x64_bin.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package jdk-17.x86_64 2000:17.0.7-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================================================
 Package                                   Arch                                      Version                                             Repository                                                Size
========================================================================================================================================================================================================
Installing:
 jdk-17                                    x86_64                                    2000:17.0.7-8                                       /jdk-17_linux-x64_bin                                    302 M

Transaction Summary
========================================================================================================================================================================================================
Install  1 Package

Total size: 302 M
Installed size: 302 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2000:jdk-17-17.0.7-8.x86_64                                                                                                                                                          1/1
  Verifying  : 2000:jdk-17-17.0.7-8.x86_64                                                                                                                                                          1/1

Installed:
  jdk-17.x86_64 2000:17.0.7-8

Complete!

The Java home by default is /usr/lib/jvm/jre-openjdk/. You can list all the contents in the directory.

$ ls -1 /usr/lib/jvm/jre-openjdk/
bin
conf
include
legal
lib
release
tapset

# OR
$ ls -1 /usr/lib/jvm/jdk-17-oracle-x64/
bin
conf
include
jmods
legal
lib
LICENSE
man
README
release

If your application needs custom setting of Java binary path, you can use /usr/lib/jvm/jre-openjdk/bin/java

Step 4: Verify Java installation

Confirm the default version of Java usable in the system.

$ java -version
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)

Let’s consider a simple Java program that just prints “Hello World” message.

vim  HelloWorld.java

Paste the following contents into the file

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Compile the Java source code using the java command:

$ java HelloWorld.java
Hello, World!

Recommended books:

Conclusion

Java offers developers a versatile and powerful programming platform for developing a wide range of applications. With its platform independence, extensive standard library, and active community, Java continues to evolve and thrive, maintaining its relevance and popularity among developers worldwide. In this article we’ve been able to install Java 17 on CentOS 7 / RHEL 7. We also demonstrated how to create a simple application, compile and execute the Java program.

YOU CAN SUPPORT OUR WORK WITH A CUP OF COFFEE


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here