Before you begin
0Start here
This course teaches Java from the very beginning: no programming experience is assumed. It explains every idea before using it, in an order where nothing is used before it has been taught, and it builds up to a 2D game of your own design. This page explains how the course works and how to set up your computer.
How the course is organised
There are eight parts. Parts 1 to 4 teach the language. Parts 5 and 6 teach how to design, test and document software. Part 7 builds a complete game with you, and Part 8 is a game of your own. The contents list on the left shows every lesson. Parts are released one at a time, and lessons that are not out yet are greyed out. The course home page says which part comes next.
How a lesson works
Lessons have their own headings, but every one is built from the same six ingredients, and each has a job.
| Ingredient | What to do with it |
|---|---|
| Explanation | Read it slowly. The aim is a picture in your head of what the computer does, accurate enough that you can predict what code will do before running it. |
| Worked examples | Every complete example program is a real file in the code folder of your course kit. Run it yourself, then change something and run it again. The output shown on the page was captured from a real run, not typed by hand. |
| Predict boxes | Stop and commit to an answer, on paper or aloud, before you reveal it. A wrong prediction is the most useful thing that can happen: it shows exactly where your picture differs from reality. |
| Errors | Each lesson shows the errors its topic produces and how to read them, so they are familiar when you meet them in your own code. |
| Exercises | New problems, graded warm-up, core and stretch. Hints are folded away; open one only after a real attempt. |
| Summary | The main points and a table of the terms the lesson introduced. If any line of it is unclear, go back before moving on. |
Where things live
You read the lessons on this website and work in a course kit: a zip file with the files you work in. Each part has its own kit, and the first lesson of each part links to it. Part 1's kit is here: download java-part1.zip.
Make a folder for the course, for example one called java-course, and unzip every part's kit into that same folder. The kits never overwrite each other's folders, so adding a later part is safe. Do not unzip the same kit a second time over work you want to keep: that puts the starter files back.
Two things to watch when you unzip. Windows' Extract All
suggests a new folder named after the zip file; change it to your course folder, so that work, code and check.py end up directly inside it. And from Part 2 on, you will be asked whether to replace check.py and README.txt: say yes. Every kit has the same two files, and nothing of yours is in them.
| In your course folder | Contents |
|---|---|
work/ | Your exercise attempts, one folder per exercise. Some folders already hold starter files; in the others you create the files yourself. |
code/ | The example programs, one folder per lesson. Safe to edit and experiment with. |
check.py | The checker, which tells you whether an exercise works. The next section explains it. |
tests/ | The test programs and expected output the checker compares your work with. Please do not open it: an exercise whose answer you have already seen teaches you much less. |
README.txt | A short summary of this page, for when you are working in the folder. |
Getting your exercises checked
The course publishes no solutions. Instead, your course kit contains a checker that tells you whether an exercise works.
- Do the exercise in its folder under
work/. The exercise box on the lesson page tells you which one. - Open a terminal in your course folder (lesson 1 shows how) and run the command the exercise box shows, for example
python check.py m01 ex3. - The checker compiles what you wrote, runs it, compares its output with what the exercise asks for, and checks that the files the exercise asks for are there.
The checker reports facts: whether your program compiles, whether its output is right, and whether the files are there. It cannot tell you whether you used the idea the lesson was teaching, or whether your code is clear. That part is yours to judge. When a check passes, reread the exercise and the part of the lesson it practises, and ask yourself whether you could explain every line of your solution to someone else. A solution that passes but works differently from the lesson's examples is still correct.
From lesson 5 onwards, most exercises ask for methods with an exact first line (name, parameter types and return type). A test program from the tests folder calls those methods with a range of values and reports each result. Your own main is still yours to experiment with, unless the exercise or its starter file says to leave it as it is.
When something is wrong, the checker shows you where: the lines where your output differs from the expected output, or the line of a test program that could not find one of your methods. That is useful once you have made a real attempt, but it gives answers away if you run it before. Write your attempt first, then check.
Some exercises ask for written notes as well as code. The checker cannot read your notes: it only confirms that the notes file is there, and a starter notes file already counts. Write the notes anyway, and write them properly: explaining something in your own words is the best test of whether you understand it.
Five habits that make this work
- Type the code; do not paste it. Typing forces you to notice every bracket and semicolon, and the mistakes you make while typing are the ones you most need to learn to fix.
- Predict, then run. Before you press Enter, say what you expect to see. Being surprised is how you find gaps.
- Break things on purpose. When an example works, remove a character and see what the computer says. You cannot damage anything, and each error you cause deliberately is one you will recognise later.
- Fix one error at a time. Fix the first one reported, then compile again. Later errors are often side effects of the first.
- Explain it aloud. If you cannot explain a line of your own program to an imaginary beginner, go back to the lesson.
Your tools
You need three things: a JDK (the Java Development Kit, which lesson 1 explains), VS Code, the editor you will write code in, and Python 3, which runs the checker. All three are free. The steps for installing them are at the end of this section.
For the first part of the course you will compile and run programs by typing commands in a terminal, even though VS Code has a Run button. That is deliberate. The commands show you the steps that the button hides, and lesson 1 is about exactly those steps.
Installing the JDK
Every program in this course was compiled and run with JDK 27, so install version 27 or newer. Free builds come from Eclipse Temurin and from Oracle. Pick your operating system, download the installer, and run it. Temurin does not build JDK 27 for Macs with an Intel processor; on one of those, use Oracle's download page instead.
Then open a new terminal (PowerShell on Windows, the Terminal app on macOS, any terminal on Linux) and type:
javac -version
If it prints a version number of 27 or higher, the JDK is ready. If the terminal says that javac is not recognised or not found, the installer did not add the JDK to your PATH, the list of folders a terminal searches for commands. Rerun the installer and look for an option such as Add to PATH
or Set JAVA_HOME
, then open a new terminal and try again.
Installing VS Code and Python
Download VS Code from code.visualstudio.com. Download Python 3 from python.org; on Windows, if the installer offers to add Python to your PATH, accept. On macOS and Linux Python 3 is often installed already. Check with:
python --version
On macOS and Linux the command is often python3 instead. If python3 --version is the one that works, type python3 wherever these pages say python.
If you are not on Windows
The terminal sessions on these pages were recorded in PowerShell on Windows, and some of what they show is specific to Windows. The javac and java commands, and the programs you write, work the same way on macOS and Linux, but watch for these differences:
- Paths use
/where Windows uses\. Where a page typescd work\m01-how-java-runs\hello, typecd work/m01-how-java-runs/hello. - Commands that are not part of Java take different options. Where a page lists a folder with
ls -Name, typels. - Windows, and macOS in its usual setup, treat capital and small letters in file names as the same; Linux does not. So a mistake in the capitals of a name can give a different error message on Linux from the one a page shows.
- The rules for quoting text and for characters such as
*in a command differ between PowerShell and the terminals of macOS and Linux. Lesson 7 and checkpoint project A point out where they describe Windows behaviour.