Java is a high-level, class-based, object-oriented programming language that is designed to have fewer implementation dependencies like one code can be written and used anywhere. It is used in a distributed environment on the internet. It is easy to read and understand. Java is popularly used in consoles, mobile applications, software development, and game development. Java is free for personal use. 

There are three editions of java.

  1. Java Standard Edition (SE) which contains code libraries
  2. Java Enterprise Edition (EE) which has APIs like servlets
  3. Java Micro Edition (ME) used to program java in cell phones

Java Packages

  • Java Development Kit (JDK) provides and environment to develop, compile and run java applications
  • Java Runtime Environment (JRE) is a tool used to run and use java applications
  • Java Virtual Machine (JVM) is an interpreter to execute java programs line by line

We are going to deal with the Java SE platform in this guide.

The latest Java SE platform release is Java 17 LTS which includes features like 

  • Sealed Classes which restricts which classes implement which classes
  • Pattern Matching for Switch Statements
  • New API for Accessing Large Icons
  • Source details in Error Messages
  • Related Packages” on a Package Summary Page

In this guide, I will show you how to 

  • Install java 17 via repository
  • Install java 17 manually
  • Configure JAVA_HOME environment variable
  • Create a sample application

Install Java 17 (OpenJDK 17) on  KDE Neon / Kubuntu

We’ll consider two installation methods, namely;

Method 1: Install Java 17 (OpenJDK 17) on  KDE Neon / Kubuntu via Repository

First, update the package index

sudo apt update && sudo apt upgrade -y

To verify sudo status use

sudo whoami

Search and find what is available

apt-cache search openjdk

The output is as follows

Install using the following command for JRE

sudo apt install openjdk-17-jre

if prompted for disk space type Y to continue

Use the following command for JDK

sudo apt install openjdk-17-jdk

Still, you will be prompted for the disk space information, type Y to continue.

Confirm the installation by using the following command

java -version

The output is as follows

Method 2: Manually install Java 17 (OpenJDK 17) on KDE Neon / Kubuntu

Visit the downloads page to download the latest tarball file

Click on save file

Once the file is downloaded, you have to navigate to the directory where the file is stored.

Open your Konsole, and navigate to the Downloads folder using

cd Downloads

Use this to extract. For future versions, the name might change due to version change. So check the name of the file matches that in code and change if need be.

tar -xvf jdk-17_linux-x64_bin.tar.gz

The extractions output is as follows

Move the extracted file to /opt/ directory. The name of the extracted file might be different. So be sure to check the name matches.

sudo mv jdk-17.0.2 /opt/

Setting JAVA_HOME Environment variable

To set JAVA_HOME to path use the following command

export JAVA_HOME=/opt/jdk-17.0.2
export PATH=$PATH:$JAVA_HOME/bin
source ~/.bashrc

The last command is used to apply the changes immediately, other than logging out and back on the system. The output is as below.

Confirm installation

java -version
echo $JAVA_HOME

The path has been added successfully

Set Default Java Version

First list the available java versions in your system

sudo update-alternatives --config java

Select the Java version you want to use by typing the number adjacent to it. If I wanted java version 11, I would select the number 1 then press Enter.

Then confirm the version by using

java -version

The output is as below.

To go back to JDK 17, You still go through the same process as shown below.

Create a Sample Application

Create a java program file using the following command

nano hello.java

Append the following command, You can change how you want the output to read.

public class hello {
public static void main(String[] args) {
System.out.println("Hello from Technixleo!");
}
}

Save and exit the file by using ctrl + x then press y to save the file and press Enter

Compile the code using the following command

javac hello.java

Then run the program using the following command

java hello

The output is as below

Conclusion

In this guide, you have learned to install OpenJDK 17 on Kubuntu/KDE Neon via manual installation and from the repository. You have also learned to configure to set the JAVA_HOME path and how to set a default java version when you have multiple of them installed. Then later you created a simple application that you built and run.

LEAVE A REPLY

Please enter your comment!
Please enter your name here