Traditionally the first program in any language prints "Hello, World!". Let's walk through it from creating the file to seeing the output.
Creating and Running via the Command Line
Every Java program goes through the same four steps — from a source file to output on the screen.
bash
mkdir hello-java && cd hello-java
# Compile
javac HelloWorld.java
# Run (without .class extension)
java HelloWorld
# Hello, World!Anatomy of the Program
Click on any line to see what it means.
Running Without Compilation (Java 11+)
Starting with Java 11, single-file programs can be run directly — without an explicit compilation step:
bash
java HelloWorld.java
# Hello, World!Passing Command-Line Arguments
The String[] args parameter in main() receives arguments passed after the class name. Let's explore how args is parsed line by line.
bash
javac Greeting.java
java Greeting # Hello, stranger!
java Greeting Alice # Hello, Alice!Console Output Methods
Java provides several ways to write to standard output. Click each card to see an example.
Comments in Java
Java has three types of comments. Click each to see what it looks like and when to use it.