How to Install Java 9 on Ubuntu

28/12/2020
Java is not included in Ubuntu by default. There are many application that do not work without Java. So, you require to install Java for using other application and developing Java application. You can use Java by installing JRE (Java Runtime Environment) or JDK (Java Development Kit). JRE consists all required libraries, Java Virtual Machine (JVM), plug-ins, and Web Start to run any Java application. JDK consists not only JRE but all necessary tools to compile and debug Java codes. If you want to develop Java application then you have to install JDK. There are two options to install JDK on any operating system. One is OracleJDK (Oracle Java Development Kit) and another is OpenJDK (Open Java Development Kit).

Oracle JDK:

Oracle JDK was known as SUN JDK before and it was the official proprietary implementation of Java language. Now, it is maintain by Oracle team. Many new features are added in the new version of Oracle JDK. Some features are mentioned here.

  • It is available in both free and commercial version and it is under Oracle Binary Code License Agreement.
  • It includes Java plug-ins and Java Web Start.
  • It contains many third-party open-source and commercial components.
  • It is better for developing commercial Java application.

Open JDK:

Open JDK is an open source implementation of Java Standard Edition platform and it can be used as an alternative of Oracle JDK.  Some important features of OpenJDK are mentioned here.

  • It is completely free to use and it is under GPL v2 license.
  • It contains most of the necessary features of Oracle JDK to develop Java application.
  • It has the ability to update JDK packages automatically by using package manager.
  • The source code is improving regularly by the contribution of open source developer.

From the above features, it is clear that you can gain maximum facilities of Java Development Kit by using Open JDK without any cost. How you can install Java 9 using Open JDK on Ubuntu is shown in this tutorial.

Installing Java 9:

First of all, you have to check if any old version of Java is installed on your system or not.

$ java

If the following information appears then Java is not installed before. OpenJDK is the default option of installing Java on Ubuntu.

If any old version of Java is installed on your system then you have to remove it before running the installation command of Java 9. Run the following command to remove previously installed Java package.

$ sudo aptget purge openjdk*

You can install JRE or JDK based on your requirements. First, run the command to install JRE and check it is working or not. The following command will install Java version 9 using JRE package. Press ‘y’ when it will ask for permission to complete the installation process.

$ sudo apt install openjdk9jre

After completing the installation process you can check JRE package is working or not by executing the following command.

$ java version

The output of the command will show the version number of OpenJDK, Java tool for executing java code and OpenJDK VM type which can be 32-bit VM or 64-bit VM depends on your computer configuration.

It is mentioned before that JRE is used for executing Java application only. So if you need Java just for executing any games or other types of applications then the above installation is OK for you. But if you want to use Java for developing Java application then you should install JDK package of OpenJDK. You need to remove JRE, before running the command of installing JDK. The following command will remove JRE from your system

$ sudo apt install openjdk9jre

Run the command to install JDK package of OpenJDK that will install necessary compiling and debugging tools with JRE. Press ‘y’ when it will ask for permission to complete the installation process.

$ sudo apt install openjdk9jdk

Test the package is working properly or not after completing the installation process.

$ java verson

Testing Java:

Write a very simple Java code to test installed Java program. Open a text editor and write the following Java code. Remember to keep the same name for class and file name. Here, class name is ‘FirstJava’. So, the filename will be ‘FirstJava.java’.

public class FirstJava {
  public static void main(String[] args){
    System.out.println("This is my first Java program.");
  }
}

Open the terminal and go to the FirstJava.java file location.

Run javac command to compile the code and create class file. If the code compiles successfully then ‘FirstJava.class’file will be generated.

$ javac FirstJava.java

Run java command to run the class file.

$ java FirstJava

The output of the program is a simple text, “This is my first Java program”. So, the following output will appear after executing the class file.

If you are planning to use Java in your Ubuntu operating system then try the above tutorial to install Java in your system and use it.

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

Java 10 New Features

What’s New in Java 10 and What are the Future Plans? Recently Java has changed the pace of releases. Previously, it would...
28/12/2020

Install Oracle JDK 11 on CentOS 7

The latest LTS (Long Term Support) version of JDK (Java Development Kit) is version 11 which came out recently. JDK 8 and...
29/12/2020

Gradle Repositories

Gradle looks for external dependencies in the repositories. A Gradle repository is organized using group, name, and version....
28/12/2020
Bài Viết

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

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024