What is Java?

Java is a popular general-purpose programming language mostly used to build applications for a wide range of platforms. This language has been around for more than 25 years; thus it’s powerful and among the top most used programming languages in the world. Java maintains its effectiveness due to the constant improvements and strong support from the developer community. With Java, developers can write and run code from anywhere. Also known as Write Once Run Anywhere(WORA); which implies that Java code when compiled once can be run on all platforms that support Java Runtime Environment(JRE) without recompilation.

Uses of Java

  • Building Mobile applications
  • Applied in Embedded systems
  • Big data processing
  • Android applications development
  • Creating Enterprise software
  • Used in Web applications

Benefits of Java Programming Language

  • Less complex programming language
  • Supports multithreading: Large applications can be treated as multiple threads and executed concurrently
  • Offers a secure platform
  • Enforces object-oriented programming
  • Has high performance and reliability

Introduction to Java 17

Java 17 is the latest long-term support release from Java SE(Standard Edition) platform. It was released in September 2021 with added features and capabilities. JDK(Java Development Kit) 17 binaries are free to use and distribute under the oracle No-Fee Terms and Conditions License.

Feature of Java 17

  • Sealed Classes: Mainly restricts which other classes can extend and implement a sealed component.
  • New macOS Rendering pipelined: MacOS can now use Apple Metal API instead of deprecated AppleGL API.
  • Removal of RMI activation: Remote Activation Mechanism will be removed but the rest of the RMI should be preserved.
  • Pattern matching for the switch: Enhances pattern matching for switch expressions and statements.
  • Removal of Experimental AOT(ahead-of-time) and JIT(just-in-time)
  • Foreign function and memory API
  • Enhanced pseudo-random number generators

Start by upgrading the Solus system repository to ensure that all packages are up-to-date.

sudo eopkg upgrade

Install Java 17 (OpenJDK 17) on Solus

To install JDK17 start by downloading the .tar.gz archive package from the Java official store. Copy the JDK17 package link for Linux operating system from the provided list.

a) Download OpenJDK 17

On your terminal, use the wget command to download OpenJDK17 from the official site to the Solus system. In this case, we will use the link we copied from the Jdk.java.net website.

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

b) Extract OpenJDK 17

Use this command to extract the OpenJDK 17 .tar.gz file.

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

Configure and Install JDK17 on Solus

After downloading and extracting the JDK17 file, it is crucial to make configurations. Thus we should first move the file we have extracted to the opt/jdk17 directory. Use the following command.

sudo mv jdk-17.0.2 /opt/jdk17

Next, set the environment variable. In this case, you will configure the JAVA_HOME environment variable and add the bin directory to the PATH environment variable.

sudo tee /etc/profile.d/jdk.sh<<EOF
export JAVA_HOME=/opt/jdk17
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
export JAVA_HOME=/opt/jdk17
export PATH=$PATH:$JAVA_HOME/bin

Activate the PATH settings by sourcing your file using the following command.

source /etc/profile.d/jdk.sh

Confirm the location of the JDK17 directory.

echo $JAVA_HOME

Results showing the directory location is /opt/jdk17 as we have set it.

$ echo $JAVA_HOME
/opt/jdk17

After the above configurations, JDK17 and its runtime environment will have been installed successfully on Java. Verify this by checking on the Java Version.

$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Test JDK17 on Solus

Let’s test whether JDK17 is working on Solus using a simple Java program.

1. Create a Java program

Still, on your terminal, use a text editor such as nano or vim to create a java file. We will create a java file with the name Welcome using a vim text editor.

vim Welcome.java

After this file has opened, press i to edit. Then copy-paste this text.

public class Welcome {
public static void main(String[] args) {
System.out.println("First Java Program!");
}
}

Save the .java file by pressing ESC followed by:wq!

2. Compile Java File

Now, compile the code above using the javac command.

javac Welcome.java

3. Run Java File

To run a file using JDK17, type the java file name right after the word java.

java Welcome

Here is the output for the java program we created above.

$ java Welcome
First Java Program!

Wrap Up

Congratulations!JDK 17 is working correctly on your Solus system. You can continue creating, compiling, and running Java codes. Keep in mind that this article has taken you through the processes of installing, configuring, and using JDK17 on the Solus operating system. Feel free to use Java 17 and in case of any query, leave a comment.

Other Guides:

LEAVE A REPLY

Please enter your comment!
Please enter your name here