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
Introduction to Java
What Java is, where it's used, how Java code is structured, and a complete roadmap for learning Java from beginner to advanced.
Setting Up Java
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.
Data Types in Java
Master Java's 8 primitive types, their wrapper classes, type casting, String handling, and how Java stores values in memory.
Operators in Java
Run Java's operators and see what they really do: integer division, overflow, ++, short-circuit logic, bitwise and shift operators, ternary, instanceof.
Variables and Operators in Java
Learn Java variables and operators by running them: types, var, final, integer division, ++, logic and bitwise operators, Scanner input and Math.
Control Flow in Java
Master Java's decision-making and looping constructs — if/else, switch expressions, for/while/do-while loops, break, and continue.
Arrays in Java
Learn Java arrays — single and multi-dimensional arrays, array operations, sorting, searching, and the Arrays utility class.
Functions (Methods) in Java
Master Java methods — declarations, static methods, pass-by-value, varargs, recursion, lambda expressions, method references and functional interfaces.
Strings in Java
Learn Java strings by running them: immutability, == vs equals, the string pool, core methods, formatting, text blocks, and StringBuilder.
Methods in Java
Learn Java methods by running them: parameters, return values, records for multiple results, pass-by-value, scope, varargs and recursion.
Java OOP — Complete Guide
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.
Introduction to Object-Oriented Programming in Java
Start Java OOP with runnable examples: define a class, create objects, write constructors, use this, and see how static and instance members differ.
Encapsulation in Java
Learn how to protect object state with access modifiers, getters, setters, and immutable design — with production-grade Java examples.
Inheritance in Java
Learn how to build class hierarchies using extends, super, method overriding, and the Liskov Substitution Principle with real Java examples.
Polymorphism in Java
See Java polymorphism run: overriding and dynamic dispatch, coding to interfaces, why fields and static methods don't dispatch, pattern-matching switch.
Abstraction in Java
Learn how Java's abstract classes and interfaces hide complexity and let you define contracts that decouple callers from implementations.
Error Types in Java
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
Regular Expressions in Java
Learn Java regex by running it: Pattern and Matcher, find vs matches, greedy vs lazy, groups, named groups, lookarounds, flags and computed replacements.
Interfaces in Java — A Deep Dive
Go beyond the basics — learn interface segregation, default methods, functional interfaces, and how interfaces enable real-world design patterns.
Abstract Classes in Java
Master abstract classes — when to use them over interfaces, template method pattern, and how they enable shared behaviour across a class hierarchy.
Method Overloading in Java
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.
Composition vs Inheritance in Java
Learn when to favour composition over inheritance, how to use the Decorator and Strategy patterns, and how to build flexible, loosely coupled Java classes.
Generics in Java
Deep dive into Java generics — generic methods, bounded type parameters, wildcards (? extends, ? super), type erasure, and the PECS principle.
Exception Handling in Java
Learn how Java handles errors — the exception hierarchy, try/catch/finally, checked vs unchecked exceptions, throw/throws, and creating custom exceptions.
Java Streams API
Learn the Java Streams API by running it: laziness, filter, map, flatMap, sorted, reduce, Collectors grouping and partitioning, and primitive streams.
Collections Framework in Java
Master Java's Collections Framework — ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap, Queue, and PriorityQueue with practical examples.
Optional in Java
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.
File Handling in Java
Read and write files in Java using the File API, BufferedReader/Writer, FileInputStream/OutputStream, and the modern NIO.2 Path/Files API.
Records in Java
Learn Java records by running them: generated accessors and equals, compact constructors, custom methods, sealed hierarchies, and record patterns.
Java 8 Features
Master Java 8's most impactful features — lambda expressions, functional interfaces, the Streams API, method references, Optional, and the Date/Time API.
Sealed Classes and Interfaces in Java
Learn sealed classes and interfaces (Java 17+) by running them: permits, final vs non-sealed subtypes, exhaustive switch, record patterns and guards.
Multithreading in Java
Learn Java multithreading by running it: Runnable and join, race conditions, synchronized and atomics, executors, CompletableFuture, virtual threads.
JDBC — Database Access in Java
Use JDBC to query a real database from Java: connections, CRUD with PreparedStatement, SQL injection, transactions with rollback, and batch inserts.
Maven — Java Build and Dependency Management
Learn Maven — the industry-standard Java build tool for managing dependencies, project structure, build lifecycle, and producing deployable artifacts.
Gradle — Modern Java Build Tool
Learn Gradle, the fast and flexible Java build tool: Kotlin DSL build scripts, the wrapper, dependencies, tests, custom tasks and multi-project builds.
Unit Testing with JUnit 5 and Mockito
Learn JUnit 5 and Mockito by running real tests: lifecycle, assertions, assertAll, parameterized tests, stubbing, verify and ArgumentCaptor.
Logging in Java with SLF4J and Logback
Learn how to add production-grade logging to Java applications using SLF4J as the facade and Logback as the implementation.
Spring Boot — Introduction
Build and run a Spring Boot 3 app: the entry point, a REST controller, application.properties, command-line overrides, profiles and Actuator health.
Dependency Injection in Spring Boot
Run Spring's IoC container: constructor injection, two beans of one type, @Primary and @Qualifier, scopes, @ConfigurationProperties and lifecycle.
Java Project Ideas
Five Java project ideas with full descriptions, skills practiced, tech stack recommendations, and difficulty ratings to build your portfolio.
Building REST APIs with Spring Boot
Build a REST API with Spring Boot 3 and curl it: path variables, query params, JSON bodies, ResponseEntity status codes, headers, CORS and MockMvc.
Validation in Spring Boot
Validate Spring Boot 3 requests with Bean Validation: @Valid bodies, error JSON from @RestControllerAdvice, path params, nested objects, custom rules.
Spring Data JPA — Database Access
Use Spring Data JPA with H2 and watch the SQL: entities, repositories, derived and JPQL queries, paging, relationships, N+1 and transactions.
Exception Handling in Spring Boot
Handle errors in a Spring Boot 3 API: default 500s, @ResponseStatus, @RestControllerAdvice, RFC 9457 ProblemDetail responses and a safe catch-all.
Spring Security — Authentication and Authorization
Secure a Spring Boot 3 API and probe it with curl: default lockdown, SecurityFilterChain rules, BCrypt, 401 vs 403, @PreAuthorize and tests.
JWT Authentication in Spring Boot
Issue and verify JWTs in Spring Boot 3 with Spring Security's resource server: login endpoint, roles claim, forged and expired tokens, all curled.
Dockerizing Spring Boot Applications
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 Enums: Beyond Simple Constants
Master Java enums with fields, constructors, abstract methods, and methods — when to use them over constants and how they enable type-safe state machines.
Inner and Anonymous Classes in Java
Master nested classes, local classes, and anonymous classes — when to use them for event handlers, callbacks, and encapsulating helper logic.
Java Generics: Bounded Types, Wildcards, and Generic Methods
Master generics beyond basic <T> — bounded types, wildcards (? extends vs ? super), and generic methods that work across collections.
Java Date/Time API: LocalDate, LocalDateTime, and Duration
Master java.time — LocalDate, LocalTime, LocalDateTime, Duration, and Period. Replace the old Date/Calendar mess with immutable, fluent time handling.
Java NIO.2: Paths, Files, and WatchService
Learn NIO.2 by running it: Path operations, reading and writing with Files, streaming lines, copy and move, walking trees, attributes and WatchService.
Java Annotations: Custom Types and Meta-Information
Create custom annotations, understand retention policies and targets, and use reflection to read annotation metadata at runtime.
Java Reflection: Dynamic Type Inspection and Method Invocation
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 Localization: ResourceBundle and Locale Support
Internationalize Java applications with ResourceBundle — load locale-specific messages, work with Locale, and understand fallback behavior.
Advanced
Production-grade patterns for experienced engineers
SOLID Principles in Java
Learn the five SOLID design principles by running Java examples: each shows the violation, what breaks, and the refactor that fixes it.
Design Patterns in Java
Learn the most important Gang of Four design patterns with production-grade Java implementations — Singleton, Factory, Builder, Observer, and Strategy.
Generics and OOP in Java
Learn how Java generics and OOP work together — generic classes, bounded type parameters, wildcards, generic methods, and type-safe collection design.
Virtual Threads in Java
Learn Java 21 virtual threads by running them: creating them, 100,000 blocking tasks, pinning, structured concurrency and scoped values.
Java Module System (JPMS)
Build Java modules step by step: module-info.java, requires and exports, what strong encapsulation blocks, opens for reflection, services and jlink.
JVM Memory Model
See JVM memory at work: stack frames and StackOverflowError, heap limits with -Xmx, OutOfMemoryError, garbage collectors, weak references and leaks.
Advanced Concurrency in Java
Master Java's advanced concurrency — ExecutorService, CompletableFuture, Fork/Join framework, BlockingQueue, and concurrent data structures.
Java Performance Tuning
Measure before you optimise: JIT warm-up, allocation profiling, string building, boxing, presized collections, precompiled regex and a real JMH benchmark.
Java Security
Secure Java coding by running it: allowlist validation, SQL injection vs PreparedStatement, PBKDF2 hashing, SecureRandom, AES-GCM and KeyStore.
Java Interview Preparation
Essential Java interview topics — JVM internals, memory model, garbage collection, collections, multithreading, and Java 8+ questions with answers.
Advanced Testing in Java
Advanced Java testing by running it: custom JUnit 5 extensions, nested and dynamic tests, Mockito spies and strict stubs, H2 and Testcontainers.