Every Java program you will ever write goes through this toolchain, so knowing what each command does saves hours of confusion.
To write Java you need a JDK (Java Development Kit). It contains the compiler javac, the launcher java, and tools like jshell and jar. Install a Java 21 LTS build (Eclipse Temurin, Oracle JDK, Amazon Corretto and others all ship the same OpenJDK code) and check it with java -version.
Java source lives in .java files. The compiler turns them into bytecode in .class files, and the JVM (Java Virtual Machine) runs that bytecode on any operating system:
javac Hello.javaproducesHello.class.java Hellostarts a JVM and runs the class namedHello(no.classsuffix).
Since Java 11 you can skip the explicit compile step for a single file: java Hello.java compiles in memory and runs immediately. That is perfect for small experiments and scripts.
For quick one-liners use jshell, the interactive shell: type jshell, then expressions like 2 + 3 or "abc".length() and see the result instantly — no class or main required.
A few habits help from day one. Keep one public class per file, named exactly like the file (Hello lives in Hello.java). Read compiler errors from the top: the first one is usually the real cause, later ones are often follow-on noise. And when you move to real projects, an IDE (IntelliJ IDEA, VS Code with the Java extensions, Eclipse) and a build tool will run javac for you — but they are calling exactly these commands underneath.
Example
// File: Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java " + Runtime.version().feature());
}
}
// Two ways to run it from a terminal:
// javac Hello.java && java Hello (compile, then run the class)
// java Hello.java (compile in memory and run)
// Output: Hello, Java 21Remember
- The JDK = compiler (
javac) + launcher (java) + tools such asjshell javacturns.javasource into.classbytecode that runs on any JVMjava File.javaruns a single source file without a separate compile step
Watch out for
- Running
java Hello.class— the launcher takes a class name, not a file name (or a.javasource file).