Share on Social Media

Learn how to install Java on Linux 9 with our comprehensive step-by-step guide. Set up the Java Development Kit (JDK) and Runtime Environment (JRE) to start developing and running Java applications on your Linux system. #centlinux #linux #java

What is Java?

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture.

The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client–server web applications, with a reported 9 million developers. (Source: Wikipedia)

Java was originally developed by James Gosling at Sun Microsystems. It was released in May 1995 as a core component of Sun Microsystems’ Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference implementation is the OpenJDK JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions.

As of September 2022, Java 19 is the latest version, while Java 17, 11 and 8 are the current long-term support (LTS) versions.

Java vs Python

Java and Python are two of the most popular programming languages, each with its strengths and ideal use cases. Here’s a comparison of Java and Python across various dimensions:

Java

Pros:

  1. Performance: Generally faster execution due to its statically-typed nature and Just-In-Time (JIT) compiler.
  2. Robustness: Strong type-checking at compile-time helps catch errors early.
  3. Scalability: Well-suited for large, complex, and high-performance applications, especially in enterprise environments.
  4. Platform Independence: Write Once, Run Anywhere (WORA) with the Java Virtual Machine (JVM).
  5. Rich Ecosystem: Extensive libraries, frameworks (like Spring, Hibernate), and tools.

Cons:

  1. Verbosity: More boilerplate code required, which can make development slower and code harder to read.
  2. Learning Curve: Steeper learning curve due to its strict syntax and object-oriented principles.

Best for:

  • Enterprise-level applications.
  • Android app development.
  • Large-scale web applications.
  • Financial services.

Python

Pros:

  1. Simplicity: Simple and readable syntax, making it easy to learn and write.
  2. Rapid Development: Ideal for quick prototyping and development.
  3. Versatility: Wide range of applications, from web development to data science, AI, and scripting.
  4. Rich Ecosystem: Extensive libraries and frameworks (like Django, Flask, TensorFlow, Pandas).
  5. Community Support: Strong community and vast amount of resources for learning and troubleshooting.

Cons:

  1. Performance: Generally slower execution compared to Java, as it is interpreted and dynamically typed.
  2. Less Strict: Dynamically-typed nature can lead to runtime errors that are harder to debug.

Best for:

  • Web development.
  • Data science and machine learning.
  • Automation and scripting.
  • Prototyping and smaller projects.

Feature Comparison

FeatureJavaPython
TypingStatically-typedDynamically-typed
PerformanceHighModerate
SyntaxVerbose, strictConcise, readable
Learning CurveSteeperGentle
Development SpeedModerateFast
Popular FrameworksSpring, Hibernate, StrutsDjango, Flask, TensorFlow
Use CasesEnterprise apps, Android, large-scale systemsWeb development, data science, automation

Conclusion

  • Choose Java if you need a language for developing large, performance-critical applications, particularly in enterprise settings or for Android development.
  • Choose Python if you want a versatile, easy-to-learn language for rapid development, especially for web development, data science, machine learning, or automation tasks.

Both languages have their unique strengths and can often complement each other in a diverse technology stack.

Recommended Online Training: Java in 3 Hours: Java Programming Tutorial for Beginners

684904 a274 3show?id=oLRJ54lcVEg&offerid=1074652.684904&bids=1074652

Environment Specification:

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Rocky Linux release 9.0 (Blue Onyx)
  • Hostname – java-01.centlinux.com
  • IP Address – 192.168.116.130/24

Update Linux Operating System:

By following the best practice, update your Linux operating system before installing Java 19 software.

Login as root user on your Linux server by using a ssh client.

Refresh your yum cache as follows.

# dnf makecache
Rocky Linux 9 - BaseOS                          786  B/s | 3.6 kB     00:04
Rocky Linux 9 - AppStream                       1.6 kB/s | 3.6 kB     00:02
Rocky Linux 9 - Extras                          334  B/s | 2.9 kB     00:08
Metadata cache created.

Update software packages in your Linux operating system.

# dnf update -y

If the above command update your Linux Kernel then, you should reboot your operating system with new Kernel before installing Java 19 software.

# reboot

Check the Linux operating system and Kernel versions as follows.

# cat /etc/rocky-release
Rocky Linux release 9.0 (Blue Onyx)

# uname -r
5.14.0-70.26.1.el9_0.x86_64

How to install Java on Linux

Java 19 software is available to download at Oracle website.

Oracle Java Downloads
Oracle Java Downloads

Copy the URL according to your preferred platform and then you can use wget command to download the Java 19 software directly from Linux commandline.

But first, use following command to install wget utility, if it isn’t already installed on your Linux machine.

# dnf install -y wget

Now, by using following commands, download Java 19 RPM into /tmp directory.

# cd /tmp
# wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm
--2022-10-26 11:34:05--  https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm
Resolving download.oracle.com (download.oracle.com)... 104.91.72.85
Connecting to download.oracle.com (download.oracle.com)|104.91.72.85|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 169483428 (162M) [application/x-redhat-package-manager]
Saving to: ‘jdk-19_linux-x64_bin.rpm’

jdk-19_linux-x64_bi 100%[===================>] 161.63M   956KB/s    in 2m 20s

2022-10-26 11:36:27 (1.16 MB/s) - ‘jdk-19_linux-x64_bin.rpm’ saved [169483428/169483428]

After successful download, you can invoke dnf command to install Java 19 on Rocky Linux 9.

# dnf install -y jdk-19_linux-x64_bin.rpm
Last metadata expiration check: 0:18:02 ago on Wed 26 Oct 2022 11:27:06 AM CDT.
Dependencies resolved.
================================================================================
 Package       Architecture  Version                  Repository           Size
================================================================================
Installing:
 jdk-19        x86_64        2000:19.0.1-10           @commandline        162 M

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

Total size: 162 M
Installed size: 318 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : jdk-19-2000:19.0.1-10.x86_64                           1/1
  Running scriptlet: jdk-19-2000:19.0.1-10.x86_64                           1/1
  Verifying        : jdk-19-2000:19.0.1-10.x86_64                           1/1

Installed:
  jdk-19-2000:19.0.1-10.x86_64

Complete!

To verify Java 19 installation, execute java command to check the version of active Java software. (Note: You can run multiple versions of Java on a Single Linux operating system with the help of alternatives command.)

# java --version
java 19.0.1 2022-10-18
Java(TM) SE Runtime Environment (build 19.0.1+10-21)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

Java 19 software has been successfully installed. Additionally you can set the following Java environment variables.

# cat << EOF > /etc/profile.d/java.sh
> export JAVA_HOME=/usr/lib/jvm/jdk-19-oracle-x64
> export PATH=$PATH:$JAVA_HOME/bin
> EOF

Video: How to install Java on Linux 9

YouTube player

Final Thoughts

Congratulations on successfully learning how to install Java on Linux 9! With Java set up, you can now develop and run Java applications efficiently. Whether you’re working on development projects, running Java-based software, or learning Java programming, having a properly configured Java environment on your system will greatly enhance your productivity. Enjoy coding and exploring the capabilities of Java on your Linux platform! We recommend that you should buy and read Linux for Beginners: A Practical and Comprehensive Guide to Learn Linux Operating System and Master Linux Command Line by Ethem Mining.

Leave a Reply