Tuesday, May 12, 2020

How To Install Java JDK and JRE

How_To_Install_Java JDK_JRE

In the previous tutorial, we have discussed what is JVM or Java Virtual Machine. Here, we will learn other java programming terms, namely JRE and JDK. Are the two still related to the JVM and why do we need to discuss both?

Understanding JRE (Java Runtime Environment)
JRE or Java Runtime Environment is an application package containing JVM (Java Virtual Machine) and some additional libraries needed to run Java applications.

So, to run a Java application on a computer or a system, a JRE application must be installed.

Java_Runtime_Environment

In the picture above, it appears that the JRE contains a JVM plus several libraries and other files. In the JVM there is a JIT (Just-In-Time) compiler, which is a technique used by Java to improve performance when running programs.

If we only want to run Java applications and do not plan to make Java program code, then JRE is the required application. Inside the JRE, there is a java command that can be used to run Java byte code.

Unfortunately, starting from version 11 and above, Oracle no longer releases JRE separately. We have to install a package with JDK (will be discussed shortly). If you intend to install JRE only, you can use an old version of JRE, for example JRE 10 or JRE 8.

Understanding JDK (Java Development Kit)
JDK or Java Development Kit is an application package containing JVM (Java Virtual Machine) + JRE (Java Runtime Environment) + various applications for the process of making Java program code.

Java_Development_Kit
One additional command in JDK is the javac command. Javac is used to process Java program code into byte code. How to use this command we will discuss in the next few tutorials.

Oracle JDK vs OpenJDK
There are currently 2 types of JDK: Oracle JDK and OpenJDK. The two versions are very similar with slight differences in the licenses.

As the name implies, OpenJDK is the open-source version of JDK released under the GNU General Public License (GNU GPL). Open JDK is still being developed by Oracle (formerly Sun Microsystem), along with various other companies, especially RedHat.

Meanwhile, Oracle JDK is a version of OpenJDK with added several features from Oracle released under commercial license. Last January 2019, Oracle drastically changed the contents of the Oracle JDK license, especially in terms of support for corporate users.

To get updates and support, companies use Oracle JDK must pay starting at $ 2.5 per user each month. But for individual use or development, we don't need to pay to use Oracle JDK.

There are still many who do not realize this difference. I'm sure the majority of Java books or tutorials for the Windows operating system still use Oracle JDK. Because, when we visit the Oracle web, this is the JDK version they have immediately offered.

For this reason, I will use Oracle JDK throughout the discussion on this blog.

Install Oracle JDK 8 On Windows

First you have to do before installing JDK is to download the JDK 8 software on the official website. Click here.

Then scroll down to find the version of the Java SE Development Kit 8u102 (JDK-8u102-windows-x64.exe), as shown in the picture below.

download_oracle_jdk8_windows

When finished, open the file then click next.

Select the feature (follow the following picture) then click next


Wait for the progress to finish.

Determine the location where the JDK folder will be stored, then click next.


The installation process will begin and wait for it to finish.

If the installation process is complete, please click close.

Install JDK 8 On Linux (Ubuntu)

OpenJDK

Open terminal. Update system with the command:

$ sudo apt-get update

Then, do the following to install default JDK:

$ sudo apt-get install default-jdk

If you want to install a different version of Java, you just need to replace the number 8 in the command according to the desired version number.

$ sudo apt-get install openjdk-8-jdk

OracleJDK

Before installing Java oracle, you must add an Oracle PPA to your repository. Type the command below:

$ sudo add-apt-repository ppa:webupd8team/java

Then, update with the command:

$ sudo apt-get update

Next, type command for the installation. Just like OpenJDK, replace the Java version of the oracle with the desired version number. Here I install Java oracle 8.

$ sudo apt-get install oracle-java8-installer

Wait for the installation to complete. If there is a configuration request like the image below, select OK by pressing Enter.


Then on the next window, navigate to the Yes option, then press Enter.

Wait for the installation to complete.

Check java version

$ java -version

check_java_version_ubuntu

Up to this point, we have successfully installed JDK both on the Windows or Linux operating system. In the next tutorial we will learn on how to add java JDK to path.