Java Tutorials

Practical, step-by-step tutorials that teach you Java by writing real code. Every example is complete and runnable — no fragments, no "fill in the blanks."

Suggested Learning Path

If you're new to Java or want a structured approach, follow these tutorials in order. Each one builds on concepts from the previous tutorials.

Intermediate Path

Object-Oriented & Collections
  1. Classes and Objects
  2. Inheritance
  3. ArrayList
  4. HashMap
  5. JDBC (Database Connectivity)

Advanced Path

Modern Java & Frameworks
  1. Lambda Expressions
  2. Streams
  3. Spring Boot
Advertisement

Java Basics

The building blocks every Java program relies on. Start here if you're new to the language.

Java Variables

Declare, initialize, and use variables. Covers all eight primitive types, type casting, variable scope, and the difference between primitive and reference types.

Beginner ~15 min read

Java Methods

Create and call methods to organize code and make it reusable. Covers parameters, return values, method overloading, and static methods.

Beginner ~15 min read

Exception Handling

Handle errors gracefully with try-catch-finally, understand exception hierarchies, create custom exceptions, and master try-with-resources for automatic cleanup.

Beginner ~20 min read

File Handling

Read and write text files, work with CSV and properties files, traverse directories, and perform file operations using modern java.nio.file APIs.

Beginner ~25 min read

Java Logging

Use java.util.logging to record meaningful information about your program. Covers log levels, handlers, formatters, configuration files, and best practices.

Beginner ~20 min read

Object-Oriented Programming

Learn how to design programs using classes, objects, and inheritance — the core of Java's approach to software design.

Classes and Objects

Master the fundamentals of OOP: define classes with fields and methods, create objects, use constructors, and understand the this keyword.

Beginner ~20 min read

Inheritance

Create class hierarchies with extends and super, override methods, and understand when inheritance is the right tool (and when it isn't).

Intermediate ~20 min read

Collections

Work with groups of data using Java's built-in collection classes — the alternatives to fixed-size arrays.

ArrayList

Use dynamic arrays that grow and shrink automatically. Covers adding, removing, searching, sorting, and iterating over elements.

Beginner ~15 min read

HashMap

Store and retrieve key-value pairs with efficient lookups. Covers put, get, remove, iteration, and understanding how hashing works.

Intermediate ~15 min read
Advertisement

Modern Java

Functional-style programming features introduced in Java 8 and later that make code more concise and expressive.

Lambda Expressions

Write concise anonymous functions for functional interfaces. Understand the syntax, common use cases, and how lambdas enable the Streams API.

Intermediate ~15 min read

Streams

Process collections of data with filter, map, reduce, and collect operations. Covers lazy evaluation, parallel streams, and when to use (and not use) streams.

Intermediate ~20 min read

Database

Connect Java applications to relational databases to store, retrieve, and manage persistent data.

JDBC

Connect to databases, execute queries with PreparedStatement, prevent SQL injection, manage transactions, handle errors, and build a real Data Access Object.

Intermediate ~30 min read

Spring

Build production-ready Java applications with the Spring framework ecosystem.

Spring Boot

Get started with Spring Boot for building web applications and REST APIs. Covers auto-configuration, dependency injection, and building your first endpoint.

Advanced ~25 min read

How to Get the Most Out of These Tutorials

Type the code, don't copy it

Every code example in these tutorials is designed to be typed by hand. You'll learn more from typing PreparedStatement pstmt = conn.prepareStatement(sql) once than from copy-pasting it ten times. Typing builds muscle memory and forces you to notice the details — the semicolons, the capitalization, the method names.

Run every example

Reading about code without running it is like reading about swimming without getting in the water. Set up your Java environment, create a file, compile it, run it, and see the output. If the output doesn't match what's shown, figure out why — that's where the real learning happens.

Break the examples

After a working example runs correctly, change something and see what happens. What if you remove the ? from a PreparedStatement? What if you use executeQuery() for an INSERT? What if you set the log level to FINEST? Predict the result before you run it, then check. Wrong predictions teach you more than right ones.

Do the exercises

Each tutorial ends with an exercise that requires you to apply what you learned in a new context — not just repeat the examples. If you can complete the exercise without looking at the solution, you've genuinely learned the material. If you get stuck, look at the solution, close it, then write it yourself.

Follow the order

Tutorials build on each other. The JDBC tutorial assumes you understand exception handling (for try-with-resources) and logging (for proper error reporting). The Streams tutorial assumes you understand lambda expressions. Skipping ahead is fine for reference, but for learning, the suggested path works best.

13
Tutorials
100+
Code Examples
13
Hands-On Exercises

Frequently Asked Questions

Most tutorials use Java 11 features (like var for local variables and Path.of() instead of Paths.get()). Some examples show Java 8 features (Streams, lambdas) which are the foundation of modern Java. A few examples note Java 17+ features where relevant. Everything works on Java 11 and later, which covers the vast majority of current Java installations.

No. You can compile and run all examples from the command line with javac and java. That said, an IDE like IntelliJ IDEA Community Edition (free) or VS Code with the Java extension makes the process faster — autocomplete catches typos, and the debugger helps you understand what's happening inside your code.

Most tutorials use plain .java files with no build tool, so you can focus on learning the Java concept itself rather than fighting with project setup. The exceptions are the JDBC tutorial (which needs a driver dependency) and the Spring Boot tutorial (which requires Maven). Once you understand the core concepts, adding a build tool is straightforward.

It depends on your experience with statically-typed, object-oriented languages. If you know C# or C++, you can probably skim the Variables and Methods tutorials and start with Classes and Objects. If you come from Python or JavaScript, the beginner tutorials are worth reading because Java's type system, compilation model, and OOP rules are significantly different.

These tutorials cover the core Java skills that interviewers expect. But getting a job also requires practice with larger projects (see our Projects section), understanding common design patterns, and being able to discuss trade-offs (which our Interview Questions section helps with). Think of these tutorials as the foundation — you still need to build on top of them.