What you'll learn
Welcome to your very first step as a Java developer. Before we write a single line of code, this module builds the mental model that makes everything else click — what programming actually is, how your computer turns text into a running app, and why Java became one of the most important languages on the planet.
By the end of this module you'll be able to:
- Explain what programming is and how a computer runs your instructions
- Describe the difference between compiled and interpreted languages — and where Java fits
- Understand what Java is, its history, and the huge range of things it powers
- Tell apart the JDK, JRE, and JVM
- Install Java and confirm it works from the command line
- Write, compile, and run your first program
- Recognise the anatomy of every Java program, including the
mainmethod - Comment your code and follow Java's naming conventions
How to use this lesson
What is programming?
A computer is astonishingly fast but completely literal — it does exactly what it's told, nothing more. Programming is the craft of writing precise, unambiguous instructions that a computer can follow to solve a problem or perform a task.
The instructions you write in a language like Java are called source code. But a computer's processor (the CPU) doesn't understand Java — it only understands machine code, the raw numeric instructions specific to that hardware. Somewhere between your readable source code and the CPU, a translation has to happen. How that translation works is the single most important idea in this module.
Key idea
Compiled vs interpreted languages
There are two classic ways to turn source code into something a computer can run — and Java cleverly combines both.
Compiled languages (like C or C++) use a compiler to translate the entire program into machine code ahead of time, producing a file that runs directly on the CPU. That's very fast, but the result is tied to one type of operating system and processor — you have to recompile for every platform.
Interpreted languages (like Python or JavaScript) use an interpreter that reads and executes the source code line by line while the program runs. That's wonderfully portable — the same source runs anywhere the interpreter exists — but it's usually slower.
Java takes a hybrid path: you compile your code once into a portable intermediate format called bytecode, and a program called the JVM runs that bytecode on any machine — using clever tricks to make it fast.
Compiled
C · C++ · Rust
✓Very fast
—Built for one platform only
Interpreted
Python · JavaScript
✓Portable across systems
—Usually slower
Java — hybrid
The best of both
✓Portable AND fast
—Needs a JVM installed
"Write once, run anywhere"
What is Java?
Java is a high-level, object-oriented, general-purpose programming language. It was created by James Gosling and his team at Sun Microsystems and released in 1995; today it's stewarded by Oracle, with OpenJDK as the free, open-source reference implementation that most developers use.
Three decades on, Java is beloved by companies and developers because it is:
- Portable — the same program runs on any device with a JVM
- Stable & backward-compatible — code written years ago still runs today
- Fast — the JVM optimises your code aggressively while it runs
- Everywhere — with one of the largest ecosystems and job markets in tech
That combination is why Java quietly powers a huge slice of the software world — from the Android phone in your pocket to the banking systems moving money around the globe.
Java SE
The core language and standard libraries — the foundation of everything.
Jakarta EE
Enterprise APIs for large-scale web and business applications.
Android
The world's most popular mobile platform is built on Java & Kotlin.
JVM languages
Kotlin, Scala, Groovy & Clojure all compile to Java bytecode.
Different platforms, one foundation — they all run on the JVM.
How Java runs your code
Let's trace exactly what happens between typing your code and seeing it run. Every Java program travels the same path:
You write your program in a plain text file ending in .java. The compiler, javac, translates it into a .class file containing bytecode — a compact, platform-independent instruction set. Bytecode isn't human-readable source, and it isn't machine code for any specific CPU either; it's a middle language designed for one audience: the JVM.
The JVM then loads that bytecode and executes it. It starts by interpreting the bytecode, and a component called the JIT (Just-In-Time) compiler spots the "hot" parts of your program that run often and compiles them to native machine code on the fly — which is how Java achieves near-compiled speed.
Key idea
.class bytecode you build on Windows runs unchanged on macOS or Linux — because it targets the JVM, not the operating system.JDK, JRE & JVM
These three acronyms trip up almost every beginner. The trick is to see them as three layers, each one wrapping the next.
- JVM (Java Virtual Machine) — the engine that actually executes bytecode. There's a JVM built for each operating system, but they all run the same bytecode.
- JRE (Java Runtime Environment) — the JVM plus the standard libraries your programs rely on. This is everything needed to run a Java app.
- JDK (Java Development Kit) — the JRE plus the developer tools (like
javacandjshell). This is everything needed to build a Java app.
JDK — Java Development Kit
Everything you need to build Java apps.
JRE — Java Runtime Environment
Everything you need to run Java apps.
JVM — Java Virtual Machine
The engine that actually executes your bytecode.
Tip
Installing the JDK & setting up your machine
Getting ready to code takes three steps:
- Download a JDK. We recommend a recent LTS (Long-Term Support) release such as JDK 21 from Eclipse Temurin (Adoptium) or Oracle. LTS versions get years of updates, which makes them the safe default.
- Install it. Run the installer on Windows or macOS, or use a package manager (
winget,brew, orapt). - Verify it works. Open a terminal and check the version:
java -versionTwo settings make your life easier. PATH lets you run java and javac from any folder, and JAVA_HOME is an environment variable that tools like Maven, Gradle, and your IDE use to find your JDK. Most installers set PATH for you; you may need to set JAVA_HOME by hand:
# macOS / Linux (add to ~/.zshrc or ~/.bashrc)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home
export PATH="$JAVA_HOME/bin:$PATH"
# Windows (PowerShell, one-time)
setx JAVA_HOME "C:\Program Files\Eclipse Adoptium\jdk-21"'java' is not recognised?
bin folder. Close and reopen the terminal after installing, or add the JDK's bin directory to your PATH manually.The three tools: java, javac & jshell
The JDK gives you a small toolbox. For now, three tools matter:
javac— the compiler. Turns.javasource into.classbytecode.java— the launcher. Starts the JVM and runs your compiled program.jshell— the REPL. Lets you try Java one line at a time, with no full program required.
jshell (introduced in Java 9) is the fastest way to experiment. Type an expression and it shows you the answer immediately — perfect for learning:
jshell> int hours = 8;
hours ==> 8
jshell> hours * 60
$2 ==> 480
jshell> System.out.println("Learning Java!")
Learning Java!Tip
jshell whenever you want to test a snippet or check how something behaves. No class, no main method, no compile step — just instant feedback.Your first program: Hello, World!
By tradition, the first program in any language simply prints the words "Hello, World!". Here it is in Java — press Run to see its output:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}To run this yourself, save it as HelloWorld.java, then in a terminal:
javac HelloWorld.java # 1. compile -> HelloWorld.class
java HelloWorld # 2. run the programSince Java 11 you can even skip the separate compile step for a single file and run it directly with java HelloWorld.java. Try changing the message inside the quotes and running it again — that instant feedback loop is the heart of learning to code.
File name must match the class
public class name exactly, including capitalisation. A class called HelloWorld must live in a file named HelloWorld.java.Anatomy of a Java program
That tiny program has a lot going on. Let's label every part, then unpack what each one means.
public class HelloWorld1 {4
public static void main(String[] args)2 {
System.out.println("Hello, World!");3
}
}Class declaration
Every Java program lives inside a class. The file must be named HelloWorld.java to match.
The main method
Execution starts here — this exact signature is the entry point the JVM looks for.
A statement
This prints a line of text to the console. Every statement ends with a semicolon ;
Curly braces
Braces { } group code into blocks. Each opening brace needs a matching closing one.
The main method is special: it's the entry point where the JVM begins running your program. Its signature never changes, so it's worth understanding each keyword:
public— accessible from anywhere, so the JVM can call itstatic— belongs to the class itself, so no object needs to be created firstvoid— the method returns no valuemain— the exact name the JVM searches for to start the programString[] args— an array of any command-line arguments passed to the program
Inside, System.out.println(...) does the printing: System is a built-in class, out is the standard output stream (your console), and println prints its text followed by a new line. Notice the statement ends with a semicolon — in Java, every statement ends with a ;, and blocks of code are wrapped in curly braces.
Memorise this line
public static void main(String[] args) is the fixed entry point of a standard Java application. You'll type it thousands of times — it's worth committing to memory now.Comments & documentation
Comments are notes for humans that the compiler completely ignores. Java has three kinds:
// ...— a single-line comment/* ... */— a multi-line (block) comment/** ... */— a Javadoc comment that documentation tools turn into browsable HTML docs
public class Comments {
public static void main(String[] args) {
// This is a single-line comment — ignored by the compiler.
/*
This is a multi-line comment.
Handy for longer explanations.
*/
System.out.println("Comments help humans, not computers.");
}
}
/**
* This is a Javadoc comment. Tools can turn it into HTML docs.
* @author You
*/
class Calculator { }Tip
Java naming conventions
The compiler doesn't force these rules, but every professional Java developer follows them — so your code should too. Consistent naming makes code instantly readable to anyone on a team.
Classes & interfaces
PascalCase
Methods & variables
camelCase
Constants
UPPER_SNAKE_CASE
Packages
lowercase.dotted
A few extra rules the compiler does enforce:
- Names are case-sensitive —
totalandTotalare different - An identifier can contain letters, digits,
_and$, but can't start with a digit - You can't use reserved keywords (like
classorint) as names
Beyond the mechanics, aim for meaningful names: classes are usually nouns (Customer), and methods are usually verbs (calculateTotal). Good names are the cheapest documentation you'll ever write.
Recap & quick check
You've covered a lot of foundational ground. Here's what to hold onto:
Key takeaways
- Programming is writing precise, unambiguous instructions a computer can execute.
- Java source (.java) is compiled to portable bytecode (.class) that runs on the JVM — write once, run anywhere.
- Install the JDK to develop: it contains the JRE (to run) and the JVM (the engine), plus tools like javac and jshell.
- Every program has a class and a public static void main(String[] args) entry point.
- Statements end with a semicolon, blocks use curly braces, and Java follows clear naming conventions.
Quick check
1. What does the javac compiler produce from a .java file?
2. Which package do you need to install in order to DEVELOP Java applications?
3. What makes Java's 'write once, run anywhere' possible?
4. Which is the correct entry-point method signature?
5. Which of these is a valid single-line comment in Java?
Nicely done — you now understand how Java works under the hood and you've run your first program. Next up: Module 2 — Variables, Data Types & Operators, where you'll start storing and manipulating real data.