← Java roadmap

Topic 1 of 30 · Beginner

Java, JDK, JRE & JVM

How Java code is compiled and run anywhere.

Concept

Java source (.java) is compiled by javac into bytecode (.class). The JVM runs that bytecode on any operating system — 'write once, run anywhere'.

The JDK (development kit) contains the compiler and tools; the JRE contains the JVM and libraries needed to run programs; the JVM is the engine itself.

The JIT (Just-In-Time) compiler turns frequently used bytecode into native machine code at run time for speed.

Cheat sheet

PartContainsNeeded for
JDKJRE + javac, jar, jdbWriting code
JREJVM + core librariesRunning code
JVMClass loader, memory, JIT, GCExecuting bytecode

Code (Java 21)

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, AICodeDost!");
    }
}
// javac Hello.java   -> Hello.class
// java Hello

Remember

  • main must be public static void main(String[] args).
  • File name must match the public class name.
  • Bytecode is platform independent; the JVM is not.

Interview questions

Why is Java platform independent?

It compiles to bytecode, not machine code. Each platform has its own JVM that runs the same bytecode.

Why is main static?

So the JVM can call it without creating an object of the class first.

Practise Java with the AI mentor

Lesson test

Take an 8-question test on “Java, JDK, JRE & JVM” — concepts, output prediction, bug spotting and interview questions.

Can't find a Java topic you need for exams or placements? Request it and we'll add it.