Installing JDK on Linux
First, run the following command in the terminal:
sudo apt updatesudo apt updateThe sudo apt updatesudo apt update command updates the system repository with the latest packages.
To install JDK version 17, run the command:
sudo apt install openjdk-17-jdksudo apt install openjdk-17-jdkNow, we must set the JAVA_HOMEJAVA_HOME environment variable. This will allow us to use JDK tools.
First, we need to know the JDK installation path running the command:
sudo update-alternatives --config javasudo update-alternatives --config javaThe next step is to copy the path shown in the terminal and run:
export JAVA_HOME=/path/shown/in/the/terminalexport JAVA_HOME=/path/shown/in/the/terminalTo make sure everything went well, we can check the javacjavac and javajava version running:
javac -version
java -versionjavac -version
java -versionjavacjavac is the compiler/command responsible for converting Java source code into Java bytecode.
Java source code is the classes and interfaces inside .java.java files and bytecode is the JVM native code.
Difference between JVM, JRE, and JDK
JVM stands for Java Virtual Machine.
JRE stands for Java Runtime Environment.
JDK stands for Java Development Kit.
JVM and JRE execute bytecode.
JDK lets you write in Java, compile, and execute the bytecode.
JDK = JRE + developer tools.
JRE = JVM + libraries.