Install OpenJDK 8 on Debian 9 Stretch

28/12/2020
Java Development Kit or JDK is used by Java programmers all over the world. Java is a compiled language. But unlike C/C++, Java compiles Java source code into Java byte code. The JVM (Java Virtual Machine) then runs the Java byte code. Java byte code is not anything like C/C++ compiled binaries, which require recompilation when needed to run on different machines and operating systems. The Java byte code is the same no matter what operating system or machine you use to generate it. The only difference is the JVM.  The JVM is operating system and machine specific.  The JVM reads the Java byte code and converts it into machine specific codes and then runs it on that particular machine and operating system.

There are 2 implementations of JDK. One is called the Oracle JDK and the other one is OpenJDK. OpenJDK is totally open source and it does not include any proprietary component of Oracle JDK. The license of Oracle JDK and OpenJDK are not same either. Oracle JDK is more restrictive than OpenJDK. For those looking for a free and open source version of JDK, OpenJDK is the best choice for them. You won’t really see much of a difference when you run OpenJDK. The experience is almost the same. You can use exactly the same command line utilities with OpenJDK as with Oracle JDK.It is really easy to install OpenJDK 8 on Debian 9 Stretch because it is already available on the official repository of Debian 9 Stretch.

In this article, I will show you how to install OpenJDK 8 on Debian 9 Stretch. Let’s get started.

First update the package repository cache of your Debian 9 operating system with the following command:

$ sudo apt-get update

Your package repository cache should be updated.

Before you install OpenJDK 8, you must know one thing. There are two versions of OpenJDK 8 on Debian 9 Stretch official repository. One is OpenJDK 8 headless and the other one is OpenJDK 8.

The difference between OpenJDK 8 headless and OpenJDK 8 is that OpenJDK 8 headless does not install any libraries for working with graphical user interfaces. It has less dependencies. So it is perfect for headless servers where you never need any graphical user interfaces (GUIs). The OpenJDK 8 provides everything that OpenJDK 8 headless provides along with libraries that are required for working with graphical user interfaces (GUIs). In this article I will install OpenJDK 8 (not headless), but I will show you how to install the OpenJDK 8 headless version as well.

You can install OpenJDK 8 headless with the following command:

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

You can install OpenJDK 8 with the following command:

$ sudo apt-get install openjdk-8-jdk

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

The apt package manager should download and install all the required packages. It may take a while depending on your internet connection.

OpenJDK 8 should be installed shortly.

Once the installation is complete, run the following command to check if OpenJDK 8 is installed correctly.

$ javac -version

If you get similar output as shown in the screenshot below, everything should be working correctly.

Now I am going to run a simple Hello World Java program and show you that the OpenJDK 8 that I installed can indeed compile Java code.

This is the code that I am going to run.

I saved the ‘HelloWorld.java’ Java source code file to ‘$HOME/Documents/codes/’ directory as you can see from the output of ‘ls’ command.

Now you can compile the ‘HelloWorld.java’ Java source file with the following command:

$ javac HelloWorld.java

The ‘HelloWorld.java’ Java source file should be compiled. You can run the ‘ls’ command now and you should be able to see a ‘HelloWorld.class’ file as shown in the screenshot below. This is the Java byte code that I was talking about.

Now you can run the Java byte code ‘HelloWorld.class’ with the following command:

$ java HelloWorld

NOTE: Don’t include the ‘.class’ extension when you run a Java byte code file. ‘java HelloWorld.class’ is not how you should run a Java program.

You should see “Welcome to LinuxHint!” printed on the screen as shown in the screenshot below. So we can compile and run Java codes with OpenJDK 8.

This is how you install OpenJDK 8 on Debian 9 Stretch. Thanks for reading this article. Tweet us at @linuxhint for comments.

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 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

JNI Tutorial

Java Native Interface (JNI) is a home-grown programming interface that’s bundled together with the Java Software Development...
28/12/2020

Install Oracle JDK 10 on Ubuntu 18.04 LTS

How to Install Oracle JDK 10 on Ubuntu 18.04 Oracle JDK is used by Java developers to develop and test Java programs. It...
28/12/2020
Bài Viết

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

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024