Java for Beginners: a 30-lesson course
One topic per lesson, real programs with real output, the errors you will actually meet, and practice questions at the end. Follow the lessons in order, or jump to any topic.
Start with Lesson 1 →Module 1 · Getting Started
Meet Java, install the JDK and run your first program. (Lessons 1–5)
1What is Java? Features and Uses
Imagine writing one letter that every post office in the world can read, whatever language its staff speak….
2Installing the JDK and Running Your First ProgramA chef needs a kitchen before cooking. A Java programmer needs the JDK (Java Development Kit) before writing…
3JDK, JRE, JVM and WORA ExplainedThink of a DVD. The disc holds the movie in a standard format. Any DVD player can play it, whether it is a…
4JVM Architecture and JIT CompilationThink of a restaurant. The receptionist checks bookings and brings in guests (loading classes). The kitchen…
5Hello World Program Explained Line by LineThe first program looks small, but it contains the skeleton of every Java program you will ever write….
Module 2 · Building Blocks
Variables, data types, casting, input and scope. (Lessons 6–11)
6Comments, Identifiers and Keywords
Every language has three basic things: notes for people, names for things, and reserved words with special…
7Variables and LiteralsThink of labelled jars in a kitchen: sugar, salt, rice. You do not say "the white powder on the second…
8Primitive Data Types in JavaThink of containers: a tiny spice jar, a water bottle and a big drum. You choose the container to match what…
9Type Conversion and CastingPouring water from a small glass into a big jug always works. Pouring a big jug into a small glass may spill….
10Taking Input with the Scanner ClassA program that always prints the same answer is not very useful. Real programs ask the user for data: a name,…
11Escape Characters and Variable Scope in JavaThis lesson covers two things that cause many small mistakes: escape characters (how to print quotes, tabs…
Module 3 · Operators
Arithmetic, comparison, logical, bitwise and precedence. (Lessons 12–15)
12Arithmetic Operators and Increment/Decrement in Java
An operator is a symbol that tells Java to do a calculation or a comparison. The values it works on are…
13Relational and Logical Operators in JavaPrograms need to make decisions: is the student’s mark above 40? Is the user’s age between 18 and 25?…
14Bitwise and Shift Operators in JavaInside the computer every number is stored as a row of bits, each 0 or 1. For example, 12 is 1100. Bitwise…
15Assignment, Ternary Operator and Operator Precedence in JavaYou now know the arithmetic, comparison, logical and bitwise operators. This lesson covers three more things:…
Module 4 · Control Flow
Decisions, loops, patterns, break and continue. (Lessons 16–20)
16if, if-else and else-if Ladder in Java
So far every program ran line after line, in order. Real programs need to choose: if the marks are 40 or…
17switch Statement in Java (Classic and Modern)Suppose a number from 1 to 7 should print a day name. An else-if ladder works, but it repeats the same test…
18while and do-while Loops in JavaPrinting the numbers 1 to 5 needs five lines. Printing 1 to 1000 should not need a thousand. A loop repeats a…
19for Loop and Nested Loops (Patterns) in JavaWhen you know how many times to repeat, the for loop is the neatest choice. It puts the start, the condition…
20break, continue and Labelled Loops in JavaNormally a loop runs until its condition fails. But sometimes you want to stop early (you found what you…
Module 5 · Data and Methods
Arrays, Strings, methods, recursion, ArrayList and exceptions. (Lessons 21–28)
21Arrays in Java (One-Dimensional)
To store the marks of 100 students you would not create 100 separate variables. An array stores many values…
22Multidimensional Arrays in JavaMarks of 3 students in 4 subjects, a chessboard, a seating chart, a matrix in mathematics: all of these are…
23Strings and the String Pool in JavaNames, messages, passwords, addresses: most real data is text. Java stores text in the String class. A String…
24String Methods and StringBuilder in JavaLesson 23 showed what a String is. This lesson shows what you can do with one: search it, cut it, change its…
25Methods and Method Overloading in JavaYou have written all your code inside main so far. Long programs written that way become impossible to read….
26Recursion Basics in JavaImagine standing in a queue and wanting to know your position. You ask the person ahead: "What is your…
27ArrayList and Wrapper Classes in JavaAn array has a fixed size. If you do not know how many marks, names or messages you will receive, you have to…
28Exception Handling Basics in JavaIn earlier lessons you saw programs crash with messages like ArithmeticException or NumberFormatException….
Module 6 · Objects and Revision
Classes and objects, then mini-programs to revise everything. (Lessons 29–30)