The JDK and Your First Program
What the JDK actually contains, and writing the "Hello, World" every Java program starts from.
2 min read
Before you can write Java, you need the JDK — the Java Development Kit. It's easy to see "JDK", "JRE", and "JVM" thrown around interchangeably, but they're three different things with a clear relationship.
JDK vs. JRE vs. JVM
- JVM (Java Virtual Machine) — the engine that actually runs compiled Java bytecode. This is what makes Java portable across operating systems.
- JRE (Java Runtime Environment) — the JVM plus the standard library classes needed to run Java programs. If all you need is to run a Java app, this used to be enough.
- JDK (Java Development Kit) — the JRE plus the tools needed to develop Java: the
javaccompiler, thejavalauncher, a debugger, and more.
Modern Java distributions (like Eclipse Temurin, Oracle's own JDK, or Amazon Corretto) bundle everything as one JDK download — you don't install the JRE separately anymore. Install a JDK (Java 17 or 21 are good, current long-term-support versions), and confirm it worked:
java -version
javac -versionWriting your first program
Every standalone Java program needs a class containing a main method — that's the entry point the JVM looks for when you run the program.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}A few details worth internalizing immediately:
- The file name must match the public class name exactly, including case: this file must be saved as
Hello.java. Java enforces this at compile time. public static void main(String[] args)is a fixed signature the JVM looks for —publicso the JVM can call it from outside the class,staticso it can be called without creating an object first,voidbecause it returns nothing, andString[] argsto receive command-line arguments.System.out.println(...)prints a line to standard output, followed by a newline.System.out.print(...)does the same without the trailing newline.
Semicolons and braces
Java statements end with a semicolon, and code blocks (the body of a class, method, loop, or conditional) are wrapped in curly braces { }. Unlike Python, indentation is purely cosmetic to Java — the braces are what actually define scope. Most style guides still expect consistent indentation regardless, because unindented Java is nearly unreadable.
public class Hello {
public static void main(String[] args) {
System.out.println("Line one");
System.out.println("Line two");
}
}Every lesson from here builds directly off this skeleton — you'll always have a class and a main method (or a method called from it) to hold the code you're experimenting with.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.