Set up and Hello, World
In this lesson
- What you need (all free)
- Installing
- Your first program
- What it all means
- Compile, then run
- More printing
Java is one of the most widely used programming languages in the world. It runs banking systems, Android apps and large company software, and it is used for Information Technology in many South African high schools. Learn Java and you learn ideas that carry over to almost every other language.
Note
Java is not JavaScript. The names are similar; the languages are not. JavaScript runs inside a web browser. Java programs run on your computer, so in this course you write and run your code in VS Code, a free editor used by professionals.
What you need (all free)
| Tool | What it is |
|---|---|
| JDK (Java Development Kit) | The Java compiler and tools. Version 21 or newer |
| VS Code (Visual Studio Code) | The editor you type in |
| Extension Pack for Java | An add-on that teaches VS Code to understand Java |
You need a Windows, Mac or Linux computer. Java cannot be set up properly on a phone.
Installing
The easy way (Windows and Mac): search for "Coding Pack for Java" from Microsoft. It installs VS Code, a JDK and the Java extensions together.
Step by step (any computer):
- Install a JDK. Search for "Temurin JDK" (from Adoptium), download the latest LTS version and run the installer. Accept the default options.
- Install VS Code from code.visualstudio.com.
- Open VS Code. Click the Extensions icon on the left (four squares), search for Extension Pack for Java and click Install.
- Close VS Code and open it again.
Check that it worked. In VS Code choose Terminal → New Terminal and type:
java -versionYou should see a version number. If you see "not recognised" or "command not found", restart the computer and try again; if it still fails, reinstall the JDK.
Your first program
- Make a folder on your computer called
java-course. - In VS Code choose File → Open Folder and open it.
- Create a new file called Main.java. The capital M matters.
Type this exactly:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Now click the Run button (a triangle at the top right), or the small Run link that appears above main.
The Terminal at the bottom shows:
Hello, World!You are a Java programmer.
What it all means
| Code | Meaning |
|---|---|
public class Main | Every Java program lives in a class. Its name must match the file name: Main in Main.java |
public static void main(String[] args) | The main method: where the program starts. Type it exactly like this every time. You will understand each word by the end of the course |
System.out.println("…"); | Print a line of text |
{ } | Braces mark where a block starts and ends |
; | Every statement ends with a semicolon |
// … | A comment: a note for people, ignored by Java |
Java is case-sensitive: System is not system, and Main is not main.
Compile, then run
A computer does not understand Java directly. Two steps happen when you click Run:
- Compile. The compiler (
javac) checks your whole program and translates it into bytecode. - Run. The Java Virtual Machine (
java) runs the bytecode.
If the compiler finds a mistake, the program does not run at all. VS Code underlines the mistake in red while you type. This strictness is helpful: many errors are caught before the program ever starts.
More printing
System.out.println("Line one");
System.out.print("Same ");
System.out.print("line");
System.out.println();
System.out.println(7 * 6);println moves to a new line afterwards; print does not. Numbers have no quotes, and Java works out the answer.
Try it
- Change the message to greet yourself by name.
- Print your name, grade and school on three lines.
- Remove a semicolon. Read the red underline and the error, then fix it.
- Rename the class to
Hellowithout renaming the file. What does VS Code say?
Check yourself
What must the file be called if the class is "public class Marks"?
Marks.java. A public class and its file must have the same name, with the same capital letters.
What is the difference between print and println?
println ends the line after printing. print stays on the same line.
What are the two steps between your code and the output?
Compiling (javac turns the code into bytecode and reports errors) and running (the Java Virtual Machine runs the bytecode).


