← Learn
Learn · Java

Java basics

Ten short lessons for someone who has never written code: what a program is and a first one that runs, variables and types, maths, working with text, making decisions, loops, arrays, writing your own methods, reading what someone types and the errors Java shows you, and a small project that uses it all. Every lesson ends with questions that check you can read real code: what does it print, what’s wrong with it, which line comes next.

Part of the Java developer path.

More info

How it works

Each lesson is a short read with Java examples and what each one prints. Then practice questions: say what a snippet prints (Java’s output exactly, capitals and all), pick an answer, tap lines of code or steps into order, or tap the line of an error message that gives the cause away. You can try again as often as you like; after two misses there’s a button to show the answer. To run an example yourself, save it as Main.java (adding the public class Main and main lines around it if it doesn’t have them, and import java.util.*; at the top for lists, maps and the other collections) and run java Main.java.

What do I need to know first?

Nothing. It starts from zero. You don't need Java installed to follow along, but it helps to try the examples yourself: install a free JDK (version 21 or later, for example Eclipse Temurin) or paste them into any online Java editor. Every example that shows what it prints was compiled and run on Java 21.

Related courses

Where is my progress saved? In this browser, like the rest of the site. Nothing to sign up for.

Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates. This course isn’t made by or affiliated with Oracle. Library and tool names (Maven, Gradle, JUnit, Mockito, SLF4J, Logback, Log4j, Spring Boot) are used only to say what they are. Every shop, service, file and person in the examples is made up.