Java is a high-level, object-oriented programming language that was released in 1995 by Sun Microsystem and is currently owned by Oracle. Since its release, Java has grown to become one of the most popular and widely used programming languages.
According to the PYPL Popularity of Programming Language Index, as of September 2023, Java was the second most popular programming language in the world. Oracle also notes that as of 2019, Java was the number one language for microservices, DevOps, AI, VR, Big Data, Analytics, and chatbots.
As of December 2019, there were 45 billion active Java Virtual Machines globally. You can be sure that Java is the programming language that powers millions of critical business transactions happening daily.
At the time of its release, Java was a game changer in software development. Java introduced the ability to write code once and run it anywhere there’s a compatible Java Virtual Machine(JVM). This meant that developers did not have to write platform-specific code for different hardware architectures and operating systems, which was tedious and time-consuming.
This was a big thing then because a lot of new devices and operations systems were being developed, and thus, a language that allowed for true cross-platform development was heaven-sent.
Aside from cross-platform compatibility, which spearheaded the adoption and use of Java programming languages, Java made revolutionary design decisions that other programming languages have emulated.
For instance, Java introduced runtime memory management and automatic memory management through garbage collection to prevent memory leaks and errors. It also popularised the object-oriented paradigm and strong type-checking to catch errors in development.
Why You Might Want to Install Java on Ubuntu
As a Java developer, familiarity with the Linux operating system may give you a significant edge compared to other developers. In fact, knowledge of Linux is a valued skill among developers.
A lot of development tools are built with the Linux operating system in mind. Therefore, Linux provides you with tons of development tools to enhance your productivity and make your development work easier. It also provides a powerful shell environment for scripting, which comes in handy in automation, system administration, and batch processing.
Linux is also the most dominant server-side and cloud-computing operating system. If you want to work in server-side development, DevOps, and cloud computing, Linux is an essential skill. Considering these are also areas where the Java programming language shines, it makes sense to use Java in a Linux environment for these tasks.
The Linux operating system also opens up the world of open source to a Java developer. Java has lots of open tools, libraries, and projects. A majority, if not all, of open-source tools and libraries are designed to work on the Linux operating system, which is an open-source operating system.
Although there are lots of Linux distributions you can use, a very popular choice among Linux users is Ubuntu. Ubuntu offers a very user-friendly interface that is easy to use, even for those new to Linux.
It also offers long-term support releases and is backed by a large and active community of Users. Additionally, Ubuntu comes with a wide range of in-built development tools and is also widely supported by software vendors and cloud service providers.
Therefore, any Java developer who is looking to leverage the full power of the Linux operating system to augment their skills and development experience will benefit greatly from using Ubuntu.
How to Install Java on Ubuntu
To install and use Java on Ubuntu, there are two main components you need to install. These are:
Java Development Kit (JDK) – the JDK provides tools that, as a developer, you’ll need in order to write Java programs. It includes the Javac compiler, which compiles Java code into bytecode, and a debugger, among other development tools.
Java Runtime Environment (JRE) – the JRE contains the Java Virtual Machine(JVM) and the Java Class Library (JCL). The JRE is used to execute compiled Java programs.
When installing Java, there are two main options to choose from. First, there’s Oracle JDK, which is fully maintained by Oracle, which is the owner of Java. Oracle JDK is not open source. The other option is the OpenJDK, which is a free and open-source version.
Both Oracle JDK and OpenJDK are recognized and released by Oracle and are functionally the same. However, Oracle JDK has a more restrictive license and does not factor in community contributions. OpenJDK, being open-source, enjoys community support and is what we are going to install.
Both OpenJDK and Oracle JDK come bundled with the Java Runtime Environment, although OpenJDK allows you to install the JRE separately. Currently, the most recent and widely used long-term support OpenJDK version is version 17, which is what we will install.
To install Java in Ubuntu:
1. Check to see if you have Java installed by opening the terminal and running:
In case you don’t have Java installed, you’ll get such an output:
In case you have an older version of Java installed, continue with the tutorial to install the latest version.
2. Upgrade your apt package to the latest version by running:
sudo apt update && sudo apt upgrade -y
3. To download and install OpenJDK version 17, run:
sudo apt install -y openjdk-17-jdk
This command installs both the Java Development Kit(JDK) and the Java Runtime Environment (JRE). Wait for the download and installation to complete. This might take some time, depending on your internet speeds.
4. To check that the correct version of Java was successfully installed, run:
If the installation was successful, you should get such an output indicating that both OpenJDK version 17 and the OpenJDK Runtime Environment were installed.
5. To further confirm that the installation of the Java Development Kit was successful, you can check the version of the Javac compiler available by running:
javac is the primary compiler used to compile Java source code into bytecode for execution by the Java runtime environment.
Importance of regularly updating and maintaining Java updates and security patches
With Java installed in your system, it is important that you regularly update Java as new updates and security patches are made available. First, Java is regularly updated to improve its performance and stability and provide new features. Therefore, updating Java allows you to use the latest features in your development and get better-performing applications.
Another important reason for installing updates is security. Running outdated versions of Java can pose a security risk, as malicious actors can exploit known vulnerabilities to attack your system. Updating and installing patches also helps correct any security risks that might have been discovered before they can be exploited to your disadvantage.
To ensure your Java applications are running efficiently and securely and have minimal downtimes, make sure to regularly update the Java installed in your system and security patches as they are released.
How to Uninstall Java from Ubuntu
In case you want to uninstall Java from Ubuntu, follow the following steps:
1. Check the version of Java you have installed by running the following command in the terminal:
openjdk version "126.96.36.199" 2023-08-24
OpenJDK Runtime Environment (build 188.8.131.52+1-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 184.108.40.206+1-Ubuntu-0ubuntu122.04, mixed mode, sharing)
The output shows that we have Java 220.127.116.11 installed, which is what we installed earlier.
2. To uninstall Java
sudo apt purge openjdk-17-*
In the command above, we use purge along with apt to remove a package together with its configuration file. The package we want to remove in this case is openjdk-17-*.
The asterisk (*) is used as a wildcard character to match all packages that have names starting with openjdk-17- . In case you have a different version of Java installed, say version 11, in the above command, you’d use openjdk-11-*. The result of running the command to remove Java is shown below:
3. In the screen prompt, enter Y and press Enter to confirm that you want to uninstall Java. Wait for the installation process to complete.
4. Once completed, you can confirm Java was successfully uninstalled by running:
The output shows that Java was completely removed from Ubuntu.
Java is a very popular programming language that is known for being portable, scalable, stable, and robust. Installing Java in Ubuntu allows developers to get the best of both worlds, making it easy to use Java and its open-source resources while also developing Linux skills, which are crucial among developers. As a Java developer, consider installing Java in Ubuntu.