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:
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:
You can install OpenJDK 8 with the following command:
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.
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:
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:
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.