Free Handbook · Every example compiled & verified

Java Handbook

Learn Java the way it is written at work. Seventeen modules from your first class to a job: every example program was compiled and run with a real JDK before publishing, with its output shown exactly as it printed, and the real javac and JVM errors you will hit are explained with the fix. Variables and types, flow control, strings and arrays, methods, classes, records, inheritance, interfaces and sealed types, exceptions, collections, generics, lambdas and streams, concurrency and virtual threads, debugging, Java with Maven, Gradle, JUnit, Spring Boot, JDBC, Hibernate, Docker and Kafka, data structures and algorithms, problem-solving patterns, interview questions, a certification exam, and a resume check at the end.

0 / 142 lessons🔥 0 day streak
ShareXLinkedIn

How this handbook works

Every lesson has a complete Java program with the exact output it prints — each one compiled and run with the real Java toolchain before it was published, so what you see is what you will get when you run it yourself — a trace of what the program did line by line where that matters, and the real compiler or runtime error you will hit next, with why it happened and the fix. Lessons tick themselves as you go. Finish the handbook, sit the exam, get the certificate, then take your resume through the ATS checker against a real job posting.

17modules
142lessons
138compiled examples
72real errors explained

Module 00 · what you'll be able to do

  • Explain what the JDK, the JVM and bytecode are, and why "write once, run anywhere" is true
  • Install a JDK on macOS, Windows or Linux and check it with java -version
  • Write, compile and run a Java program from the terminal, with and without javac
  • Read the structure of a Java file: class, main method, statements, braces and comments
  • Use this handbook, its verified examples and an AI assistant without shortcutting your own learning
01

Why learn Java

Java is a general-purpose, statically typed, object-oriented language created by James Gosling at Sun Microsystems and released in 1995. You write .java source files, the compiler javac turns them into bytecode (.class files), and the Java Virtual Machine (JVM) runs that bytecode on any operating system. That is the old slogan "write once, run anywhere": the same compiled program runs on Windows, macOS and Linux without a rebuild.

Thirty years on, Java is not a legacy curiosity. A new version ships every six months, and every two years one becomes a long-term support (LTS) release that companies standardise on. This handbook teaches Java 21 LTS — records, var, switch expressions, text blocks, pattern matching and sealed types — and every example also runs unchanged on newer JDKs.

  • Backend services — Spring Boot is the most common way large companies build web APIs; banks, insurers, airlines, e-commerce and payment systems run on it.
  • Android — the Android SDK is a Java API; Kotlin is now preferred for new apps, but it runs on the same platform and millions of lines of Android code are Java.
  • Big data and streaming — Apache Kafka, Hadoop, Elasticsearch, Cassandra and Flink are written in Java, and Spark runs on the JVM. Data engineers read Java stack traces every week.
  • Enterprise and fintech — long-lived systems where a strict compiler, mature tooling and a huge hiring pool matter more than terse syntax.
RoleWhere Java shows upWhat to learn after this handbook
Backend developerREST APIs, microservices, payment and order systemsSpring Boot, JPA/Hibernate, SQL
Android developerMobile apps, SDKsKotlin, Android Studio, Jetpack
Data engineerKafka producers and consumers, Spark jobs, Flink pipelinesKafka, Spark, Scala
QA / SDETSelenium and API test suitesJUnit 5, TestNG, REST Assured
In real jobs
Most Java job descriptions list "Core Java" first — exactly what Modules 01–10 cover: types, OOP, exceptions, collections, generics, lambdas, streams and concurrency. Interviewers test those basics hard because frameworks like Spring hide them until something breaks.
02

JDK, JRE and JVM in plain English

JDK (Java Development Kit)
What you install as a developer: the compiler javac, the launcher java, tools like jshell and jar, plus the standard library.
JVM (Java Virtual Machine)
The program that loads bytecode and runs it. It interprets hot code at first, then compiles it to fast native machine code at runtime (the JIT compiler).
JRE (Java Runtime Environment)
The JVM plus the standard library, without the compiler. Modern JDKs no longer ship a separate JRE download; you just install the JDK.
Bytecode
The portable instruction format inside .class files. The same bytecode runs on every JVM, on every operating system.
LTS
Long-term support release. Java 8, 11, 17, 21 and 25 are LTS versions; most companies run one of them in production.
  1. 1
    1. You write source

    Main.java — plain text, human readable.

  2. 2
    2. javac compiles

    javac Main.java checks every type and writes Main.class (bytecode). Type errors stop here, before the program ever runs.

  3. 3
    3. The JVM runs it

    java Main starts a JVM, loads Main.class, and calls its main method.

Which JDK should you download?
Any OpenJDK build works — Eclipse Temurin (Adoptium), Amazon Corretto, Microsoft Build of OpenJDK, Oracle OpenJDK. They are built from the same source. Pick Temurin 21 if you have no reason to choose otherwise.
03

Install Java on macOS, Windows and Linux

Install a JDK, then open a new terminal and check that both the launcher and the compiler are on your PATH. If you see a version number from both commands, you are done.

bashmacOS (Homebrew)
brew install --cask temurin@21
java -version
javac -version
bashWindows (PowerShell, winget)
winget install EclipseAdoptium.Temurin.21.JDK
# close and reopen PowerShell, then:
java -version
javac -version
bashLinux (Ubuntu / Debian)
sudo apt update
sudo apt install openjdk-21-jdk
java -version
javac -version
bashExpected output (numbers vary)
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
javac 21.0.4
"java: command not found" or "javac is not recognized"
The JDK is installed but not on your PATH. Open a fresh terminal first — installers change PATH only for new sessions. On Windows, check that JAVA_HOME points at the JDK folder and that %JAVA_HOME%\bin is in Path. On macOS with several JDKs, /usr/libexec/java_home -V lists them.

For an editor, IntelliJ IDEA Community Edition is free and is what most Java teams use; VS Code with the "Extension Pack for Java" is a lighter option. Both can download a JDK for you if you skipped the step above.

04

Your first Java program

Create a folder, save the code below as Main.java (the file name must match the public class name, capital M included), and run it.

javaMain.java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
        System.out.println("2 + 3 = " + (2 + 3));
    }
}
Outputcompiled & run with real Java
Hello, Java!
2 + 3 = 5
Your turn

Add a third line that prints your name. Then remove the brackets around 2 + 3 and predict the output before you run it (hint: it becomes 2 + 3 = 23 — string joining happens left to right).

bashTwo ways to run it
# Classic: compile to bytecode, then run the class
javac Main.java     # writes Main.class
java Main           # note: no .java, no .class

# Since Java 11: run a single source file directly
java Main.java      # compiles in memory and runs

Single-file launch is perfect for learning and for every example in this handbook. Real projects compile with a build tool (Maven or Gradle, Module 12).

VisualizeWhat happens when you run itStep 1 / 5
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
System.out.println("2 + 3 = " + (2 + 3));
}
}
Line 1

The JVM loads the class Main. Every piece of Java code lives inside a class.

Variables now

nothing yet

All 5 steps as a table
StepLineWhat happenedVariables now
11The JVM loads the class Main. Every piece of Java code lives inside a class.
22It looks for the exact signature public static void main(String[] args) and calls it. args holds any command-line arguments — none here.args = []
33System.out is the standard output stream; println prints the text and a newline.
44The brackets run first: 2 + 3 is the int 5. Then "2 + 3 = " + 5 joins a String and an int into a new String.
55The end of main — the program exits with status 0.
Error you will hit

';' expected — the first compiler error everyone meets

java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!")
    }
}
Main.java:3: error: ';' expected
        System.out.println("Hello, Java!")
                                          ^
1 error
Why the compiler said that

Every Java statement ends with a semicolon. The compiler reads the file, reaches the end of line 3, and the caret ^ points at exactly where it expected the ;. Read the file name, the line number, then the caret.

The fix

Add the semicolon at the end of the statement.

java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
Error you will hit

package system does not exist — Java is case-sensitive

java
public class Main {
    public static void main(String[] args) {
        system.out.println("Hello, Java!");
    }
}
Main.java:3: error: package system does not exist
        system.out.println("Hello, Java!");
              ^
1 error
Why the compiler said that

System is a class; system (lower case) is a different name that does not exist, so the compiler guesses you meant a package called system. Java treats Main, main and MAIN as three unrelated names.

The fix

Capitalise class names exactly: System, String, Math.

java
System.out.println("Hello, Java!");
05

How a Java program is structured

A Java source file holds one or more classes. A class holds fields (data) and methods (behaviour). A method holds statements, each ending in ;. Curly braces { } mark where each class, method or block starts and ends — indentation is for humans only, the compiler ignores it.

javaMain.java
public class Main {
    // a field: data that belongs to the class
    static String language = "Java";

    // a method other code can call
    static int square(int n) {
        return n * n;
    }

    // the entry point the JVM calls
    public static void main(String[] args) {
        System.out.println("Learning " + language);
        System.out.println("7 squared is " + square(7));
        System.out.print("print() does not add a newline, ");
        System.out.println("println() does.");
    }
}
Outputcompiled & run with real Java
Learning Java
7 squared is 49
print() does not add a newline, println() does.
Your turn

Add a method static int cube(int n) and print cube(3) from main.

PieceMeaning
public class MainA class visible everywhere. One public class per file, and the file must be named after it.
publicThe JVM (outside your class) must be allowed to call main.
staticmain belongs to the class itself, so the JVM can call it without creating an object first.
voidmain returns nothing.
String[] argsAn array of the command-line arguments: java Main.java a b gives ["a", "b"].
System.out.println(...)Print to standard output followed by a newline.
Naming conventions (followed by every Java team)
Classes in PascalCase (OrderService), methods and variables in camelCase (totalPrice), constants in UPPER_SNAKE_CASE (MAX_RETRIES), packages in lower case (com.example.shop). The compiler does not enforce them; code review does.
Newer JDKs: a shorter main
JDK 25 finalised "compact source files": void main() { IO.println("Hi"); } with no class around it. It is great for scripts, but Java 21 codebases, interviews and tutorials still use the full public static void main(String[] args) form, so this handbook does too.
06

Comments

Java has three comment styles. The compiler throws all of them away; they exist for the next person who reads the code — often you, six months later. Comment why something is done, not what the line obviously does.

javaMain.java
/**
 * A Javadoc comment: tools turn these into HTML API docs,
 * and IDEs show them when you hover over the class or method.
 */
public class Main {
    public static void main(String[] args) {
        // A single-line comment runs to the end of the line.
        int seats = 42; // it can also follow code

        /* A block comment
           can span several lines. */
        System.out.println("Seats: " + seats);
        // System.out.println("This line is commented out, so it never runs");
    }
}
Outputcompiled & run with real Java
Seats: 42
Your turn

Remove the // in front of the last println and run it again — "commenting out" code is how you switch a line off while debugging.

Quick check

You save a program as hello.java but it declares public class Main. What happens with javac hello.java?

07

How this handbook works

Seventeen modules, each its own page, from variables to a job-ready resume. The rail on the left lists them; the bar at the top and the pill at the bottom-left track your progress. A lesson ticks itself when you reach its end, and the tick survives closing the tab — no account needed.

  • Examples are compiled and verified. Java cannot run inside a web page, so every example here is a complete program that was compiled and run with a real JDK before publishing. The output shown under it is exactly what it printed — copy the program into your IDE or save it as Main.java and run java Main.java to see the same result.
  • "Your turn" tasks under each example ask you to change one thing. Do them — predicting output before you run is the fastest way to learn.
  • Traces step through a program line by line with the variables at each step — used where loops, recursion and method dispatch get confusing.
  • Error cards show the real javac or JVM message, why it happened, and the fix. Module 11 collects the fifteen most common.
  • Interview questions appear where the topic is taught and are collected in Module 15, tiered junior, mid and senior.
  • The handbook ends with a certification exam (25 questions, 70% to pass), then the ATS resume checker with a real job posting.
The floating board
The pill at the bottom-left opens a board with every key term from the module you are on and a tutor you can ask about the code on the page. It is a language model — check what it says against a real compiler.
ModulesYou learn
01–04Variables, types, operators, input, if/switch, loops, strings, arrays, methods, recursion
05–07Classes, objects, encapsulation, records, inheritance, interfaces, polymorphism, exceptions
08–10Collections, generics, lambdas, streams, concurrency
11–14Debugging, Java with real tools (Maven, Spring Boot, JUnit, Docker…), data structures and algorithms, problem solving
15–16Sixty interview questions, resume, portfolio, the certificate
08

Using AI to learn Java (without cheating yourself)

An AI assistant can write a working Java class in seconds. That is exactly why you should type the code yourself while learning. The goal is not the code; it is the model in your head — why == on two Strings can be false, why a method cannot change the caller's variable, why a checked exception must be declared. That model is what an interviewer tests and what lets you fix a production stack trace at 2 a.m.

Do this

  • Paste a real compiler error and ask what it means, then fix it yourself
  • Ask "why does this print false?" after you have made your own guess
  • Write the class first, then ask for a code review
  • Ask for three edge-case inputs your method might get wrong

Not this

  • Ask for the answer to a "Your turn" task and paste it in
  • Accept code you cannot explain line by line
  • Wrap an error in try/catch and ignore it because the AI suggested it
  • Use it during an interview or the certification exam

Ready? Module 01 starts with variables, the eight primitive types, operators and reading keyboard input.

Every lesson in the handbook

17 modules · 142 lessons · each one ticks itself when you reach the end.

00Getting Started0 / 8
01Fundamentals0 / 6
02Flow Control0 / 6
03Strings & Arrays0 / 8
04Methods0 / 6
05Classes & Objects0 / 7
06Inheritance & Interfaces0 / 8
07Exceptions0 / 8
08Collections0 / 8
09Generics, Lambdas & Streams0 / 8
10Concurrency0 / 9
11Errors & Debugging0 / 7
12Java + Tools0 / 10
13Data Structures & Algorithms0 / 14
14Problem Solving0 / 12
15Interview Questions0 / 11
16Job Ready0 / 6

Frequently asked questions

Is this Java handbook free?
Yes — every module, every example and the certification exam are free, with no signup and no paywall. The exam asks you to sign in with Google so the certificate can carry your name.
Do I need to know another programming language first?
No. Module 01 starts from variables and types and assumes nothing. If you already know another language you will move faster, and the handbook calls out where Java differs, such as integer division, == on Strings and checked exceptions.
Do I need to install anything?
Yes — a JDK (the Java Development Kit), and Module 00 shows how to install one and run your first program. The examples on this page do not run in the browser; instead, each example program was compiled and run with a real JDK before publishing, and the output shown is exactly what it printed, so you can paste it into Main.java and get the same result. The framework labs in Module 12 need libraries, so they are shown as clearly marked snippets.
Which version of Java does this handbook use?
Java 21, the current long-term-support release, including its modern features: records, switch expressions, sealed types, pattern matching and virtual threads. Every example is verified on a current JDK, and older-version differences are pointed out where they matter.
Is there a certificate?
Yes. Pass the 25-question exam (35 minutes) with 70% or more and generate a SolutionGigs Java certificate with your name, score, date and a certificate ID — download it, print it or add it to LinkedIn.
Is Java hard to learn for a beginner?
Java is more verbose than Python — you declare types and wrap everything in a class — but that strictness helps beginners: the compiler catches many mistakes before the program runs and tells you the exact line. Most people can write small programs within a week and object-oriented code within a month of steady practice.
Should I learn Java or Python first?
If you want backend, Android or big-data jobs, start with Java — it is what those codebases are written in, and it teaches types and OOP properly. If you want data science, scripting or machine learning, start with Python. The fundamentals transfer either way.
Which Java version should I install?
Install JDK 21 (an LTS release) or anything newer. Every example in this handbook uses Java 21 features and runs unchanged on JDK 21, 25 and later.

Finish the Java handbook, then get hired

Sit the exam for your certificate, run your resume through the ATS checker, and see the jobs that ask for exactly this.

Check my resume
Found this course useful? Share it.
ShareXLinkedIn

Comments

0

Join the conversation. Sign in to leave a comment — we'd love to hear your thoughts.