JVM (Java Virtual Machine)

  • Java is platform independent because it run on the JVM, on top of any system. In other words, any system that has a JVM can run Java applications.
  • JVM however is platform dependent.
  • In order to run a Java application in the JVM,
    • Supply the program byte-code
    • Specify the first file (it should have a main method)
      • Expected signature of the main method: public static void main

JRE (Java Runtime Environment)

  • JRE = JVM + libraries
  • Enough to run Java applications

JDK (Java Development Kit)

  • Used to develop Java applications
  • JDK = JRE + Other programs (javac, etc.)
  • Developers use JDK, while users need only JRE to run the applications
  • Thus Java is referred to as “WORA” (Write Once Run Anywhere)

Java setup


A Simple Java Program

// Hello.java file
 
class Hello { // Need a class as Java is strictly object-oriented
	public static void main (String a[]) { // JVM looks for this method
		System.out.println("Hello World");
	}
}
javac Hello.java # Compiles and creates a new Hello.class file
java Hello # Executes using JVM

Refs

  1. https://www.youtube.com/watch?v=NHrsLjhjmi4