1. Introduction
The PDF in the document is HERE.
The code in this document is HERE.
This document is a product of Anthropic’s IA Claude. It is the Kotlin port of the course “Learning the Java 25 Language Through Examples” (October 2026), which itself is a port of the course “Learning the C# 14 Language with .NET 10 (October 2026), a rewrite of the course “Learning the C# Language, Version 3.0, with the .NET 3.5 Framework” written by Serge Tahé in May 2008. It retains the outline, examples, and main thread of that course, and rewrites them in today’s Kotlin:
- The document uses Kotlin 2.4 (version 2.4.20, September 2026), with JDK 25, the latest long-term support (LTS) version of Java (LTS). Kotlin is a language for the Java Virtual Machine: it produces the same intermediate code as Java and directly uses all of its libraries. Readers of the Java course will therefore find the same classes from JDK (files, networking, threads, dates, etc.) and the same frameworks (JUnit, Spring, Jackson, Hibernate, Spring Boot), used from another language;
- where the two languages differ, this document does more than just translate. Kotlin offers its own solutions to issues that Java handles differently: null safety built into the type system, properties, data classes, extension functions, operator overloading, functional types, default parameter values and named arguments, and the [when] expression. Conversely, Kotlin does not have checked exceptions or [static] members. These differences are presented in detail, often by comparing Kotlin code with Java code;
- the chapter on asynchronous programming takes on a different character: whereas Java uses [CompletableFuture] classes and virtual threads, Kotlin offers coroutines, along with [suspend] functions, the [launch] and [async] constructors, and structured concurrency. This is Kotlin’s answer to the C# [async] / [await] from the original course;
- the libraries are the ones currently used on the JVM: [JUnit 6] and [kotlin.test] for testing, [Spring Framework 7] for dependency injection, [Jackson 3] for JSON, [kotlinx.coroutines] for coroutines, the driver [MySQL Connector/J] for JDBC, [Hibernate 7] for object-relational mapping, and [Spring Boot 4] for web services; the projects are built using [Gradle], whose scripts are themselves written in Kotlin.
This document is not a comprehensive course. Like the materials from which it is derived, it is intended for readers who are already familiar with programming and wish to learn the basics of Kotlin. It uses examples: more than two hundred programs (more than three hundred Kotlin files), most of them short, with line-by-line comments.
1.1. Kotlin from 2011 to 2026
Kotlin was introduced in July 2011 by the company JetBrains, the publisher of IDE, IntelliJ, and IDEA, which was seeking a language that was more concise and safer than Java for writing its own tools, yet compatible with it: A Kotlin program is compiled into bytecode, executed by the Java Virtual Machine (the JVM), and can call Java code as well as be called by it. The name comes from an island in the Gulf of Finland, near Saint Petersburg, where the team that designed it worked.
Key milestones:
- 2016: Kotlin 1.0, the first stable version, with the accompanying compatibility commitment;
- 2017: Google announced official support for Kotlin for developing Android apps; in 2019, Android became “Kotlin first”: Kotlin is the recommended language for new Android apps;
- 2018: Kotlin 1.3, which stabilized coroutines, Kotlin’s answer to asynchronous programming (Chapter 9);
- The language is developed by JetBrains; the Kotlin Foundation, founded in 2017 by JetBrains and Google, oversees its evolution, with each stage subject to public proposals (the “KEEP,” Kotlin Evolution and Enhancement Process);
- 2024: Kotlin 2.0, featuring a new compiler called K2, which is faster and better at tracking types in the code (smart type casting);
- Kotlin also targets platforms other than JVM: JavaScript, WebAssembly, and native code (Kotlin/Native, iOS). This document covers only Kotlin on JVM;
- since version 2.0, a new language version (2.1.0, 2.2.0, 2.3.0, 2.4.0…) is released approximately every six months; in between, a tooling release (2.x.20) provides improvements to the tools and the standard library without changing the language. This document uses version 2.4.20, released in September 2026. New features are often introduced first as experimental; they must then be explicitly enabled (via a compiler option or the [@OptIn] annotation) before they become stable in a subsequent release.
The following table summarizes the main new language features presented in this document and indicates the chapter in which they appear:
Version | Year | Major New Features | Chapter |
Kotlin 1.0 | 2016 | null safety, properties, data classes, extension functions, lambdas, [when], operator overloading | 3, 4, 7 |
Kotlin 1.1 | 2017 | type aliases [typealias], bound references [object::function], coroutines (experimental) | 4, 7 |
Kotlin 1.3 | 2018 | Stable coroutines, [main] function with no parameters | 2, 3, 9 |
Kotlin 1.4 | 2020 | Functional interfaces [fun interface], conversions SAM of Kotlin interfaces | 7 |
Kotlin 1.5 | 2021 | Unsigned types ([UInt]…) and stable classes [value class], sealed interfaces | 3, 4 |
Kotlin 1.9 | 2023 | [..<] operator, [entries] property of enums, [data object] | 3, 12 |
Kotlin 2.0 | 2024 | K2 compiler: more accurate smart type conversions | 4 |
Kotlin 2.2 | 2025 | Liveness conditions in [when] ([is Int if x > 0 ->]), interpolation with multiple [$] | 3, 5 |
Kotlin 2.3 | 2025 | Java 25 support | 2 |
Kotlin 2.4 | 2026 | In version 2.4.20, the [kotlinr] launcher replaces the [kotlin] command | 2 |
In terms of libraries and tools, the new features include: the build tool [Gradle] and its Kotlin scripts ([build.gradle.kts]), the Kotlin standard library collections and their higher-order functions, sequences, coroutines, and streams ([Flow]), as well as major Java ecosystem frameworks used from within Kotlin: JUnit, Spring, Jackson, Hibernate, and Spring Boot.
1.2. Document Contents
The document includes the following chapters:
- Chapter 2: Setting up the development environment (JDK 25, IntelliJ IDEA, the compiler [kotlinc], Gradle);
- Chapter 3: Language Fundamentals (types, null safety, operators, [if] and [when], loops, exceptions, enumerations, function parameters);
- Chapter 4: Classes, properties, inheritance, sealed classes, operator overloading, interfaces, generics, data classes, extension functions;
- Chapter 5: Commonly Used Kotlin Classes: Strings, Arrays, Collections, Sequences, Text and Binary Files, JSON with Jackson, Regular Expressions;
- Chapter 6: Layered architectures, unit testing with JUnit 6, and dependency injection with Spring;
- Chapter 7: Functional types, lambda expressions, and events;
- Chapter 8: Execution threads, synchronization, and virtual threads;
- Chapter 9: Asynchronous Programming with Coroutines;
- Chapter 10: Database Access with JDBC;
- Chapter 11: Hibernate;
- Chapter 12: Web Programming (TCP/IP, clients and servers TCP, HTTP with [HttpClient], SMTP);
- Chapter 13: Web Services with Spring Boot;
- Chapter 14: Going Further;
- Appendices: Installing Laragon and MySQL, dependencies used by Gradle projects.
1.3. The Common Thread: Tax Calculation
A single problem is revisited throughout this document: calculating the income tax for a taxpayer who has only their salary to report. The tax bracket used is the original one (2003 income): it is no longer current, but it suffices for our purpose, which is to write the same application in several different ways. It is implemented in nine versions:
Version | Chapter | Content |
1 | 3 | A single program: validated input, calculation, display |
2 | 4 | Classes and interfaces: [TaxBracket], [ITax], [AbstractTax], [HardwiredTax] |
3 | 5 | calculation data read from a text file or a JSON file |
4 | 6 | A layered architecture ([dao], [business], [ui]) within a single program |
5 | 6 | One Gradle subproject per layer, unit tests, and integration of layers via dependency injection |
6 | 10 | A [dao] layer that reads data from a MySQL database using JDBC |
7 | 11 | a [dao] layer written with Hibernate |
8 | 12 | A TCP tax calculation server and its client |
9 | 13 | a REST web service for tax calculation, a console client, and a web client |
Starting with version 5, subsequent versions reuse the layers from version 5 and replace only the layer that has changed: this is the whole point of the layered architecture presented in Chapter 6.
1.4. Examples
The code in this document is organized in a single folder named [kotlin-oct-2026], with one subfolder per chapter. Each subfolder is a Gradle project (or a Gradle build consisting of multiple projects) that can be opened as-is in IntelliJ and IDEA:
Each small program is a Kotlin file, stored in a package that bears its name ([src/main/kotlin/basics04/Basics04.kt], package [basics04]). You can run it in IntelliJ IDEA by clicking the green triangle next to its function [main], or from the command line using Gradle ([gradlew -q run -Pmain=basics04.Basics04Kt], Chapter 2). Programs that require an external library (Jackson, JUnit, Spring, the MySQL driver, Hibernate, Spring Boot) must declare it in their project’s [build.gradle.kts] file: Gradle downloads it from the Maven Central repository during the first build.
All programs in this document were compiled without errors or warnings by the Kotlin 2.4.20 compiler, using the option that treats all warnings as errors ([allWarningsAsErrors]), and then run on JDK 25. The results reproduced in this document are those from these executions. Those of Chapters 2 to 4 were obtained with the French language and country settings (fr-FR), as on a French Windows machine: formatted floating-point numbers are displayed with a decimal comma, and dates are in French; those of the following chapters were obtained with English settings. Two notes:
- error messages from the Kotlin compiler and JDK (exception messages) are in English: they have no French translation;
- the examples were run on Linux. For the most part, this makes no difference: Kotlin on JVM is cross-platform. The few differences (file paths with / instead of \, terminal commands, [./gradlew] instead of [gradlew]) are noted where they appear.
The results of multithreaded, asynchronous, or network programs, as well as the measured durations, may vary from one run to another: the comments focus on what is reproducible.
1.5. Sources
The primary sources for this document are:
- the official Kotlin documentation: the website https://kotlinlang.org/docs (language guide, tutorials, “What’s New” pages for each version) and the standard library documentation: https://kotlinlang.org/api/core/kotlin-stdlib/;
- the coroutines guide: https://kotlinlang.org/docs/coroutines-guide.html;
- language evolution proposals (KEEP): https://github.com/Kotlin/KEEP;
- the Java documentation for API and SE 25, for the classes in JDK: https://docs.oracle.com/en/java/javase/25/;
- the Gradle documentation (https://docs.gradle.org) and the documentation for each library: JUnit (https://docs.junit.org), Spring (https://spring.io/projects), Hibernate (https://hibernate.org/orm/documentation/), Jackson (https://github.com/FasterXML/jackson);
- two reference books: “Kotlin in Action” by Sebastian Aigner, Roman Elizarov, Svetlana Isakova, and Dmitry Jemerov (Manning, 2nd edition) and “Effective Kotlin” by Marcin Moskała; for threads, “Java Concurrency in Practice” by Brian Goetz et al. (Addison-Wesley) remains an excellent read.