Home | Lessons | × Java lessons JVM JRE JDK Packages Encapsulation Abstraction Enums Java quizes JVM - JRE - JDK
JVM - JRE - JDK
♦ A Java program can be written once and then run on many different devices.
♦ You do not write Java programs for Windows, Unix, a Palm PC or any other device.
♦ You write Java programs to run on a .. JVM (Java Virtual Machine)!
The usual Process of a Programmer

The process of creating a program is as follows:
  1. Write the source code with a simple text editor
  2. Save the file with the name e.g. Person.java
  3. Compile the program using the javac.exe file (included in JDK)
  4. After the compilation, the Person.class file will be created.
  5. Person.class file contains the bytecode.
  6. bytecode can be run on any computer that has the JRE or the JDK installed.
JVM - JRE - JDK. Which one should I install?
♦ JVM (Java Virtual Machine) is a set of specifications (not a program) on how to be executed a Java program. It is platform independent.
♦ JRE (Java Runtime Environment) is the implementation of the JVM for specific platform (eg. java.exe for Windows).
   It is responsible for executing the bytecode of your program (eg. Person.class) in the specific computer. It is platform dependant.
♦ JDK (Java Developer's Kit) - also known as SDK (Standard Developer's Kit) is JRE plus Tools (Compiler, Debugger etc)
   for creating and executing Java programs. It concerns the programmers and is platform dependant.

♦ JRE is what you would install if you just want to run Java programs.
♦ If you are actually going to write and run Java programs, you will only need to install the JDK (Java Developer's Kit).
   The JDK contains the JRE plus all the necessary development tools (mainly the Java compiler).
Setting the PATH
♦ After installing the JDK you will need to set the PATH environment variable of your operating system,
   so that you can easily run the compiler and the JRE from the command line.
♦ The value, you need to add to the PATH, is the full name of the bin folder where the JDK installed
   (eg. "C:\Program Files\Java\jdk-23\bin").
Checking the Installation
♦ After setting the PATH, check if the compiler and the JRE are working.
♦ Open a command line and type:
C:\Users\alex>javac -version ↻ javac 23 C:\Users\alex>java ↻ ... C:\Users\alex>
If the responses are friendly, everything is OK.
♦ Typically you must write javac.exe (for the compiler) and java.exe (for the JRE), instead of just javac and java
   However in command line usually you can omit the .exe extension.
The first program. Write → Compile → Run

Write

♦ Write (or just copy - paste) in a plain text editor the following Java program:
Person.java
 Copy code
W3Schools Compiler Compiler
public class Person {
public static void main (String [] args) { System.out.println ("Hello World");
}
}
♦ Save it (eg. in folder C:\Users\alex) with the exact same name
   as the public class and .java extension (Person.java)

Compile

Open a command line and go to the folder where you save the file. Type:
C:\Users\alex>javac Person.java ↻ C:\Users\alex>
If there are no compiler errors, the command line will appear again silently.

Run

From the command line again, type:
C:\Users\alex>java Person ↻ Hello World C:\Users\alex>
Excellent

♦ Alternatively, you can go to an online compiler, such as W3Schools Compiler, to experiment.
   In this case, there is no need to install anything from Java.