Programming and IT

How to learn Java from scratch

Java is a strictly typed language behind banking systems, the servers of large services and Android apps. The strictness slows you down at first, but the compiler catches many mistakes before the program ever runs. This plan takes about six months at an hour a day and leads from your first program to a small backend application.

Updated
In this article

What to install#

You need a JDK — the development kit that contains the javac compiler and the runtime. Take the current LTS release: OpenJDK builds are free (Eclipse Temurin, for example). For an editor, use IntelliJ IDEA Community Edition: it is free and flags errors right in the editor as you type.

Build your first program by hand once, without the IDE, so you see what actually happens:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java");
    }
}

javac Hello.java turns the source into the bytecode file Hello.class, and java Hello runs it. Recent JDKs can also run a single-file program directly: java Hello.java.

Weeks 1–6: the language without objects#

Primitive types (int, long, double, boolean, char) and how they differ from reference types, strings and why they are immutable, operators, if, switch, loops, arrays, static methods. Pay attention to integer division and overflow: 7 / 2 in Java gives 3, and the sum of two large int values can turn negative. Good tasks for this stage: converting between number bases, finding prime numbers, working with an array of grades.

Weeks 7–12: object-oriented programming#

Classes and objects, fields and constructors, encapsulation, inheritance, interfaces and abstract classes, polymorphism. Work through equals, hashCode and toString — many beginners trip over them. To make it stick, model a small domain: a library with books, readers and loans, or bank accounts with transfers and a transaction history. Learn exceptions at the same time: checked and unchecked, and your own exception classes.

Weeks 13–18: the standard library and tools#

  • Collections: ArrayList, HashMap, HashSet, LinkedList — when to use which and how fast their operations are.
  • Generics, lambdas and the Stream API.
  • Building a project with Maven or Gradle: dependencies and the src/main/java / src/test/java layout.
  • Unit tests with JUnit 5.
  • Git: a branch per task and meaningful commits.

Weeks 19–26: towards backend development#

Talk to a database through JDBC, then get to know Spring Boot — the framework most server-side Java is written with. The final project is a REST service, such as a to-do list or a book tracker: a few endpoints, storage in PostgreSQL, tests and a README that explains how to run it.

Projects worth showing#

  • a console tic-tac-toe game with win detection and tests;
  • a CSV parser that computes statistics and writes a report to a file;
  • bank accounts with transfers and protection against going below zero;
  • a Spring Boot REST service backed by a database.

How to check yourself#

Run the tests before every commit and keep them green. Turn on static analysis in the IDE and deal with every warning instead of switching it off. Solve problems on sites with automatic checking, such as Exercism or LeetCode, choosing Java as your language. Every two weeks, reread your old code and rewrite whatever you would now do differently — it is the clearest sign of progress. If you can, post a project for code review in a Java community, for example the Code Review site on Stack Exchange.

Step-by-step plan

  1. Week 1 — JDK and IDEInstall an LTS JDK and IntelliJ IDEA, compile your first program by hand with javac.
  2. Weeks 2–6 — language basicsTypes, operators, conditions, loops, arrays, static methods.
  3. Weeks 7–12 — OOPClasses, inheritance, interfaces, equals and hashCode, exceptions.
  4. Weeks 13–18 — library and toolsCollections, generics, the Stream API, Maven or Gradle, JUnit 5, Git.
  5. Weeks 19–26 — a backend projectJDBC, Spring Boot, a REST service with a database and tests.

Start learning this in your own space

The plan goes into your repository: tick off stages, keep notes — the change history shows how far you have come.

Start the plan

Check yourself

1.What does this Java code print: System.out.println(7 / 2);

2.What does this Java code print: System.out.println("a" + 1 + 2);

3.What is the value of the expression 10 % 3 in Java?

Sources

Was this helpful?

More articles

Programming and IT How to learn Python from scratch Python is a good first programming language: code reads almost like text, and the standard library covers most everyday tasks. This plan takes you from installing the interpreter to your own scripts covered by tests in about four months, at roughly an hour a day. Programming and IT How to learn SQL from scratch SQL is the query language of relational databases. Developers, analysts, testers and managers who want to pull numbers themselves all need it. Basic queries take a few weeks to learn; working confidently with complex reports takes two or three months of practice. Below is the order of topics and ways to train on a real database. Programming and IT How to learn Linux from scratch Linux runs most servers, containers and countless devices, so developers, testers, analysts and system administrators all need the command line. The easiest way to learn it is not by reading lists of commands but by working in the terminal every day and solving small practical tasks. Below is a sequence of topics for two to three months. Programming and IT How to learn JavaScript from scratch JavaScript runs in every browser and, through Node.js, on the server too. It is easy to start — you can run code right in the browser console — but it has plenty of surprising corners, from type coercion to asynchronous code. The plan below takes three to four months and assumes you already know basic HTML and CSS or are learning them alongside. Programming and IT How to learn machine learning from scratch Machine learning means building models that find patterns in data and make predictions from them. Starting with neural networks is tempting, but it is safer to go from the bottom up — from Python and math to classic algorithms, honest evaluation and only then deep learning. Without a technical background, expect six months to a year of regular study. Programming and IT C++ from scratch C++ is a compiled language used wherever speed and direct access to memory matter — game engines, browsers, databases, firmware. It is harder to get into than Python, but you can build your first working program on the very first evening.

More solutions