Installing Java - Understanding JDK, JRE, JVM, PATH, CLASSPATH, JAVA_HOME and JRE_HOME

The purpose of this article is to inform you how to install java, how to run your first java program, and to understand what happens when you run a java program.

What is JVM, JRE, JDK?

JVM - Java Virtual Machine

JRE - Java Runtime Environment

JDK - Java Development Kit

In short JDK contains JRE which contains JVM.

alt text

alt text

Install Java

Well first check if you have it installed already. Open up terminal or powershell/cmd. Run the command java -version. If you have it installed then it should look something like this: alt text If it is not installed it should look something like this: alt text

If you are on windows or mac you can install the jdk (java + development tools) from here

You can also install it from the command line for macs and linux: sudo packageManagerName install oracle-java. For example sudo apt-get install java

You should be able to run java and javac from the command line by this point.

What exactly happens when you run a program? What is PATH, JAVA_HOME, JRE_HOME, and CLASSPATH?

Let’s see an example

  1. 1.Open up a text editor and save this java program. Name it ~ ~
    public class HelloWorld {
     public static void main(String[] args) {
         // Prints "Hello, World" to the terminal window.
         System.out.println("Hello, World");
  2. 2.Open up a terminal and moved to where you save cd location/subdir
  3. 3.Compile and then run the program javac and java HelloWorld alt text

So what exactly is going on when you type the command java and javac. Where is this running from? For this we need to understand what environmental variables are.




Post originally posted on 2017-07-30 21:00:00 -0400

Post last modified on

comments powered byDisqus