Skip to main content
Programming Languages

Java Tutorial with Examples.

Java tutorial for working engineers: core OOP principles, generics, concurrency and automated test runners, taught through small runnable programs.

Beginner

Start here — no prior experience needed

17 lessons
java beginner
5 min read

What Java is, where it's used, how Java code is structured, and a complete roadmap for learning Java from beginner to advanced.

java beginner
5 min read

Install the JDK, set up IntelliJ IDEA, write and run your first Java program, and understand how javac and the JVM turn source code into output.

java beginner
5 min read

Master Java's 8 primitive types, their wrapper classes, type casting, String handling, and how Java stores values in memory.

java beginner
5 min read

Run Java's operators and see what they really do: integer division, overflow, ++, short-circuit logic, bitwise and shift operators, ternary, instanceof.

java beginner
5 min read

Learn Java variables and operators by running them: types, var, final, integer division, ++, logic and bitwise operators, Scanner input and Math.

java beginner
5 min read

Master Java's decision-making and looping constructs — if/else, switch expressions, for/while/do-while loops, break, and continue.

java beginner
5 min read

Learn Java arrays — single and multi-dimensional arrays, array operations, sorting, searching, and the Arrays utility class.

java beginner
5 min read

Master Java methods — declarations, static methods, pass-by-value, varargs, recursion, lambda expressions, method references and functional interfaces.

java beginner
5 min read

Learn Java strings by running them: immutability, == vs equals, the string pool, core methods, formatting, text blocks, and StringBuilder.

java beginner
5 min read

Learn Java methods by running them: parameters, return values, records for multiple results, pass-by-value, scope, varargs and recursion.

java beginner
5 min read

A map of Java OOP from classes and objects through the four pillars to SOLID and design patterns, with one runnable program showing every pillar.

java beginner
5 min read

Start Java OOP with runnable examples: define a class, create objects, write constructors, use this, and see how static and instance members differ.

java beginner
5 min read

Learn how to protect object state with access modifiers, getters, setters, and immutable design — with production-grade Java examples.

java beginner
5 min read

Learn how to build class hierarchies using extends, super, method overriding, and the Liskov Substitution Principle with real Java examples.

java beginner
5 min read

See Java polymorphism run: overriding and dynamic dispatch, coding to interfaces, why fields and static methods don't dispatch, pattern-matching switch.

java beginner
5 min read

Learn how Java's abstract classes and interfaces hide complexity and let you define contracts that decouple callers from implementations.

java beginner
5 min read

Understand Java's error types — compile errors, checked and unchecked exceptions, and Errors — with real stack traces showing how to read each one.

Intermediate

For developers with core concepts down

38 lessons
java intermediate
5 min read

Learn Java regex by running it: Pattern and Matcher, find vs matches, greedy vs lazy, groups, named groups, lookarounds, flags and computed replacements.

java intermediate
5 min read

Go beyond the basics — learn interface segregation, default methods, functional interfaces, and how interfaces enable real-world design patterns.

java intermediate
5 min read

Master abstract classes — when to use them over interfaces, template method pattern, and how they enable shared behaviour across a class hierarchy.

java intermediate
5 min read

Learn Java method overloading by running it: how the compiler picks an overload through widening, boxing and varargs, plus the null and remove(int) traps.

java intermediate
5 min read

Learn when to favour composition over inheritance, how to use the Decorator and Strategy patterns, and how to build flexible, loosely coupled Java classes.

java intermediate
5 min read

Deep dive into Java generics — generic methods, bounded type parameters, wildcards (? extends, ? super), type erasure, and the PECS principle.

java intermediate
5 min read

Learn how Java handles errors — the exception hierarchy, try/catch/finally, checked vs unchecked exceptions, throw/throws, and creating custom exceptions.

java intermediate
5 min read

Learn the Java Streams API by running it: laziness, filter, map, flatMap, sorted, reduce, Collectors grouping and partitioning, and primitive streams.

java intermediate
5 min read

Master Java's Collections Framework — ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap, Queue, and PriorityQueue with practical examples.

java intermediate
5 min read

Learn Optional<T> by running it: create, unwrap with orElse vs orElseGet, transform with map, flatMap and filter, use it in streams, and avoid misuse.

java intermediate
5 min read

Read and write files in Java using the File API, BufferedReader/Writer, FileInputStream/OutputStream, and the modern NIO.2 Path/Files API.

java intermediate
5 min read

Learn Java records by running them: generated accessors and equals, compact constructors, custom methods, sealed hierarchies, and record patterns.

java intermediate
5 min read

Master Java 8's most impactful features — lambda expressions, functional interfaces, the Streams API, method references, Optional, and the Date/Time API.

java intermediate
5 min read

Learn sealed classes and interfaces (Java 17+) by running them: permits, final vs non-sealed subtypes, exhaustive switch, record patterns and guards.

java intermediate
5 min read

Learn Java multithreading by running it: Runnable and join, race conditions, synchronized and atomics, executors, CompletableFuture, virtual threads.

java intermediate
5 min read

Use JDBC to query a real database from Java: connections, CRUD with PreparedStatement, SQL injection, transactions with rollback, and batch inserts.

java intermediate
5 min read

Learn Maven — the industry-standard Java build tool for managing dependencies, project structure, build lifecycle, and producing deployable artifacts.

java intermediate
5 min read

Learn Gradle, the fast and flexible Java build tool: Kotlin DSL build scripts, the wrapper, dependencies, tests, custom tasks and multi-project builds.

java intermediate
5 min read

Learn JUnit 5 and Mockito by running real tests: lifecycle, assertions, assertAll, parameterized tests, stubbing, verify and ArgumentCaptor.

java intermediate
5 min read

Learn how to add production-grade logging to Java applications using SLF4J as the facade and Logback as the implementation.

java intermediate
5 min read

Build and run a Spring Boot 3 app: the entry point, a REST controller, application.properties, command-line overrides, profiles and Actuator health.

java intermediate
5 min read

Run Spring's IoC container: constructor injection, two beans of one type, @Primary and @Qualifier, scopes, @ConfigurationProperties and lifecycle.

java intermediate
5 min read

Five Java project ideas with full descriptions, skills practiced, tech stack recommendations, and difficulty ratings to build your portfolio.

java intermediate
5 min read

Build a REST API with Spring Boot 3 and curl it: path variables, query params, JSON bodies, ResponseEntity status codes, headers, CORS and MockMvc.

java intermediate
5 min read

Validate Spring Boot 3 requests with Bean Validation: @Valid bodies, error JSON from @RestControllerAdvice, path params, nested objects, custom rules.

java intermediate
5 min read

Use Spring Data JPA with H2 and watch the SQL: entities, repositories, derived and JPQL queries, paging, relationships, N+1 and transactions.

java intermediate
5 min read

Handle errors in a Spring Boot 3 API: default 500s, @ResponseStatus, @RestControllerAdvice, RFC 9457 ProblemDetail responses and a safe catch-all.

java intermediate
5 min read

Secure a Spring Boot 3 API and probe it with curl: default lockdown, SecurityFilterChain rules, BCrypt, 401 vs 403, @PreAuthorize and tests.

java intermediate
5 min read

Issue and verify JWTs in Spring Boot 3 with Spring Security's resource server: login endpoint, roles claim, forged and expired tokens, all curled.

java intermediate
5 min read

Prepare a Spring Boot 3 app for containers: layered jars, env-var config, JVM memory flags, health probes and graceful shutdown, plus a Dockerfile.

java intermediate
5 min read

Master Java enums with fields, constructors, abstract methods, and methods — when to use them over constants and how they enable type-safe state machines.

java intermediate
5 min read

Master nested classes, local classes, and anonymous classes — when to use them for event handlers, callbacks, and encapsulating helper logic.

java intermediate
5 min read

Master generics beyond basic <T> — bounded types, wildcards (? extends vs ? super), and generic methods that work across collections.

java intermediate
5 min read

Master java.time — LocalDate, LocalTime, LocalDateTime, Duration, and Period. Replace the old Date/Calendar mess with immutable, fluent time handling.

java intermediate
5 min read

Learn NIO.2 by running it: Path operations, reading and writing with Files, streaming lines, copy and move, walking trees, attributes and WatchService.

java intermediate
5 min read

Create custom annotations, understand retention policies and targets, and use reflection to read annotation metadata at runtime.

java intermediate
5 min read

Learn the Java Reflection API by running it: get Class objects, list members, invoke methods, read private fields, and hit the module-system wall.

java intermediate
5 min read

Internationalize Java applications with ResourceBundle — load locale-specific messages, work with Locale, and understand fallback behavior.

Advanced

Production-grade patterns for experienced engineers

11 lessons
java advanced
5 min read

Learn the five SOLID design principles by running Java examples: each shows the violation, what breaks, and the refactor that fixes it.

java advanced
5 min read

Learn the most important Gang of Four design patterns with production-grade Java implementations — Singleton, Factory, Builder, Observer, and Strategy.

java advanced
5 min read

Learn how Java generics and OOP work together — generic classes, bounded type parameters, wildcards, generic methods, and type-safe collection design.

java advanced
5 min read

Learn Java 21 virtual threads by running them: creating them, 100,000 blocking tasks, pinning, structured concurrency and scoped values.

java advanced
5 min read

Build Java modules step by step: module-info.java, requires and exports, what strong encapsulation blocks, opens for reflection, services and jlink.

java advanced
5 min read

See JVM memory at work: stack frames and StackOverflowError, heap limits with -Xmx, OutOfMemoryError, garbage collectors, weak references and leaks.

java advanced
5 min read

Master Java's advanced concurrency — ExecutorService, CompletableFuture, Fork/Join framework, BlockingQueue, and concurrent data structures.

java advanced
5 min read

Measure before you optimise: JIT warm-up, allocation profiling, string building, boxing, presized collections, precompiled regex and a real JMH benchmark.

java advanced
5 min read

Secure Java coding by running it: allowlist validation, SQL injection vs PreparedStatement, PBKDF2 hashing, SecureRandom, AES-GCM and KeyStore.

java advanced
5 min read

Essential Java interview topics — JVM internals, memory model, garbage collection, collections, multithreading, and Java 8+ questions with answers.

java advanced
5 min read

Advanced Java testing by running it: custom JUnit 5 extensions, nested and dynamic tests, Mockito spies and strict stubs, H2 and Testcontainers.