Installing the JDK
The Java Development Kit (JDK) includes the compiler (javac), the runtime (JVM), and the standard library. Download it from Oracle or use OpenJDK.
Example
# Check if Java is installed
java --version
javac --version
# macOS (with Homebrew)
brew install openjdk
# Ubuntu/Debian
sudo apt install default-jdk
# Windows: Download from oracle.com/java or adoptium.net
# Set JAVA_HOME environment variable
# Add to PATH: $JAVA_HOME/bin Compile and Run
Java source files (.java) are compiled to bytecode (.class files), which runs on the JVM.
Example
// 1. Create a file: App.java
public class App {
public static void main(String[] args) {
System.out.println("Java is running!");
}
}
// 2. Compile
// javac App.java → creates App.class
// 3. Run
// java App → executes the bytecode
// Single-file shortcut (Java 11+)
// java App.java → compile and run in one step 