Phase 1 · BeginnerModule 1~35 min read

Introduction to Programming & Java

What programming really is, how computers run your code, what makes Java special, and writing your very first program.

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 main method
  • Comment your code and follow Java's naming conventions

How to use this lesson

New to coding? Don't rush. Read once for the big picture, then come back and try each command yourself. Understanding beats memorising — and every example below has a Run button so you can see the result instantly.

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

A program is just a list of instructions. The real skill of programming is breaking a problem into steps so simple and precise that a machine can follow them without guessing.

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.

Comparison

Compiled

C · C++ · Rust

Source code
compiler
Machine code
Runs directly on the CPU

✓Very fast

—Built for one platform only

Interpreted

Python · JavaScript

Source code
interpreter
Executed line by line

✓Portable across systems

—Usually slower

Java — hybrid

The best of both

Source code
javac
Bytecode
JVM + JIT
Fast & portable

✓Portable AND fast

—Needs a JVM installed

Java sits between the two worlds: portable like an interpreted language, fast like a compiled one.

"Write once, run anywhere"

This hybrid design is the reason for Java's famous motto. You build your program once, and the same bytecode runs on Windows, macOS, Linux, and beyond — no changes needed.

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.

The Java ecosystem

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.

Four major worlds, all built on the same virtual machine.

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:

The Java build & run pipeline
HelloWorld.java
Source code
You write this
javac
Compiler
Translates it
HelloWorld.class
Bytecode
Portable format
JVM
Virtual machine
Runs the bytecode
Any OS
Win · macOS · Linux
Same program, anywhere
Source → bytecode → JVM → any operating system.

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

The .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 javac and jshell). This is everything needed to build a Java app.
JDK contains JRE contains JVM

JDK — Java Development Kit

Everything you need to build Java apps.

javacjshelljarjavadocdebugger

JRE — Java Runtime Environment

Everything you need to run Java apps.

Core librariesjava.langjava.util

JVM — Java Virtual Machine

The engine that actually executes your bytecode.

Class loaderBytecode executionGarbage collectorJIT compiler
To develop Java, install the JDK — it includes all three layers.

Tip

Rule of thumb: to develop, install the JDK. It contains everything else, so you never have to install the JRE or JVM separately.

Installing the JDK & setting up your machine

Getting ready to code takes three steps:

  1. 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.
  2. Install it. Run the installer on Windows or macOS, or use a package manager (winget, brew, or apt).
  3. Verify it works. Open a terminal and check the version:
Terminal
java -version
If you see a version number, Java is installed correctly.

Two 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:

Terminal
# 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?

If the terminal says the command isn't found, your PATH isn't pointing at the JDK's 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 .java source into .class bytecode.
  • 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
jshell> int hours = 8;
hours ==> 8

jshell> hours * 60
$2 ==> 480

jshell> System.out.println("Learning Java!")
Learning Java!

Tip

Fire up 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:

HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Your very first Java program.

To run this yourself, save it as HelloWorld.java, then in a terminal:

Terminal
javac HelloWorld.java   # 1. compile  -> HelloWorld.class
java HelloWorld         # 2. run the program

Since 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

The file name has to match the 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.

Hello World, dissected
public class HelloWorld1 {4
    public static void main(String[] args)2 {
        System.out.println("Hello, World!");3
    }
}
1

Class declaration

Every Java program lives inside a class. The file must be named HelloWorld.java to match.

2

The main method

Execution starts here — this exact signature is the entry point the JVM looks for.

3

A statement

This prints a line of text to the console. Every statement ends with a semicolon ;

4

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 it
  • static — belongs to the class itself, so no object needs to be created first
  • void — the method returns no value
  • main — the exact name the JVM searches for to start the program
  • String[] 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
Comments.java
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

Great comments explain why, not what. If the code already shows what is happening, don't restate it — instead, capture the reasoning that the code can't.

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.

Naming at a glance

Classes & interfaces

PascalCase

BankAccountRunnable

Methods & variables

camelCase

getBalanceuserName

Constants

UPPER_SNAKE_CASE

MAX_USERSPI

Packages

lowercase.dotted

com.mastercoding.app

A few extra rules the compiler does enforce:

  • Names are case-sensitive — total and Total are different
  • An identifier can contain letters, digits, _ and $, but can't start with a digit
  • You can't use reserved keywords (like class or int) 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.