Java: getting started
How the JDK, JVM and bytecode fit together, and the smallest program you can compile and run.
Write once, run anywhere
Java source compiles to bytecode, not machine code. The JVM (Java Virtual Machine) runs that bytecode, so the same .class file works on any platform that has a JVM.
| Term | What it is |
|---|---|
| JDK | Java Development Kit — compiler (javac), launcher (java), tools |
| JRE | Java Runtime Environment — what a user needs to run Java |
| JVM | The virtual machine that executes bytecode |
| Bytecode | Portable instructions in .class files |
Your first class
Java is class-based: every statement lives inside a class. The file name must match the public class name exactly, including capitalisation.
// Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}javac Hello.java # produces Hello.class
java Hello # runs it; note: no .class suffixpublic static void main(String[] args) is the entry point: public so the runtime can call it, static so no instance is needed, and the String[] parameter carries command-line arguments.
Modern base syntax
// since Java 10: local variable type inference
var name = "Ada";
var scores = new int[]{90, 85, 77};
// text blocks (Java 15+) for multi-line strings
var message = """
Line one
Line two""";
// var still needs a type; it is not dynamic typing
// name = 42; // compile error💡
var is compile-time inference, not JavaScript-style dynamic typing. Use it when the right-hand side makes the type obvious.FAQ
Which Java version should I learn?
A current LTS release (17 or 21). LTS versions get long-term support and are what employers run.
Why does my program say 'could not find or load main class'?
Usually a package mismatch: the file declares
package com.example; but you run java Hello. Run it by its full name (java com.example.Hello) from the source root.Related
Java types and variables Classes, records and interfaces
Last refreshed 2026-09-17.