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 ~ HelloWorld.java ~
    HelloWorld.java
    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 HelloWorld.java cd location/subdir
  3. 3.Compile and then run the program javac HelloWorld.java 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.

LINKS/SOURCES:

  1. http://www3.ntu.edu.sg/home/ehchua/programming/howto/environment_variables.html
  2. https://www.javatpoint.com/difference-between-jdk-jre-and-jvm
  3. http://www.journaldev.com/546/difference-jdk-vs-jre-vs-jvm
  4. https://stackoverflow.com/questions/1906445/what-is-the-difference-between-jdk-and-jre

[top]

Post originally posted on 2017-07-31 01:00:00 +0000

Post last modified on

comments powered byDisqus