Install OpenJDK 9 on Ubuntu

28/12/2020
Java is a high level programming language. It is a compiled programming language. But it doesn’t compile Java code to machine language directly. It compiles to Java byte code using the Java compiler. Then a Java Virtual Machine or JVM is used to translate the Java byte code into machine language. As a computer can only understand machine language, it is the JVM that is responsible for running a Java program. JVM is platform dependent. That is, JVM on Windows is different than JVM on Linux or Mac OS. JVM on Linux is different than JVM on Mac OS or Windows and so on. But the Java byte code is platform independent. So Java can be compiled once and run everywhere. That is why it is so popular and billions of devices have Java installed.

Programmers use Java Development Kit or JDK to compile and run Java programs. JDK is a collection of tools required to develop, debug, package Java applications.

In this article, I will show you how to install OpenJDK, a free and open source version, on Ubuntu 17.10 Artful Aardvark. Let’s get started.

Installing OpenJDK 9:

OpenJDK 9 is in the ‘universe’ repository of official Ubuntu package repository. Before you can install OpenJDK 9, you must enable Ubuntu ‘universe’ package repository.

To do that, first open “Software & Updates” from the Application Menu.

It should look like this.

Make sure you have all of these repositories, ‘main’, ‘universe’, ‘restricted’, ‘multiverse’ enabled.

Once you’re done enabling them, click on “Close”.

Now open a Terminal (Ctrl+Alt+T on Ubuntu) and run the following command to update the package repository cache of your Ubuntu operating system.

$ sudo apt-get update

The package repository cache should be updated.

There are two versions of OpenJDK 9 in the official package repository of Ubuntu. OpenJDK 9 headless and OpenJDK 9.

The difference between OpenJDK 9 headless and OpenJDK 9 is that, OpenJDK 9 headless does not come with any Java libraries for working with graphical Java applications. It is best for server environment where graphical user interface (GUI) is not required. It also requires less memory to run.

OpenJDK 9 comes with Java libraries for working with graphical user interface (GUI). It requires more memory to run.

I will install OpenJDK 9 in this article. But I will also show you how to install OpenJDK 9 headless as well.

To install OpenJDK 9 headless, run the following command:

$ sudo apt-get install openjdk-9-jdk-headless

To install OpenJDK 9, run the following command:

$ sudo apt-get install openjdk-9-jdk

Now press ‘y’ and press <Enter> to continue.

OpenJDK 9 should be installed.

Verifying OpenJDK 9 Installation

Now that OpenJDK 9 is installed. You can run the following command to check whether the Java compiler provided by the OpenJDK 9 package is working or not.

$ javac -version

You can see from the following screenshot that the version of Java compiler I am using is 9.

Now run the following command to check whether the Java Virtual Machine (JVM) provided by the OpenJDK 9 package is working or not.

$ java -version

You can see from the screenshot below that the version of JVM is 9. So everything is working correctly.

Now I am going to write a simple Java program to test whether I can compile and run Java programs with OpenJDK 9.

I created a Hello.java Java source file as you can see in the screenshot below.

Here is the source code for my super simple Java program.

I put the Hello.java file in the ~/Documents/codes directory as you can see from the screenshot below.

To compile Hello.java file, from the directory where the Java source file is, run the following command.

$ javac Hello.java

The ‘Hello.java’ Java source file should be compiled and it should create a ‘Hello.class’ Java byte code file as you can see from the screenshot below.

Now to run the Java byte code, all you have to do is run the following command.

$ java Hello

NOTE: Do not include .java extension when running a Java program with ‘java’ command.

You should see the output of the ‘Hello.java’ program.

So everything is working well.  This is how you install OpenJDK 9 on Ubuntu 17.10 Artful Aardvark. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install OpenJDK 8 on Debian 9 Stretch

Java Development Kit or JDK is used by Java programmers all over the world. Java is a compiled language. But unlike C/C++,...
28/12/2020

Install OpenJDK 9 on Ubuntu

Java is a high level programming language. It is a compiled programming language. But it doesn’t compile Java code to...
28/12/2020

Eclipse Java Tutorial

Eclipse Integrated Development Environment is an incredible open source compilation of tools, projects and co-existing working...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024