Practical Kotlin Deep Dive
Unpacks the "how" and "why" behind Kotlin from core language fundamentals and internal mechanisms to API design. Covers Kotlin fundamentals, standard library, coroutines, kotlinx libraries, compiler internals, and Kotlin Multiplatform.
This book goes beyond the API surface and dives into Kotlin under the hood: walks through real implementations of Kotlin functions, demystifies the generated bytecode, and explains how the Kotlin compiler interprets the language.
Everything You Need to Master Kotlin
What Sets This Book Apart
From in-depth explanations to practical code references
๐In-Depth Explanations
Each topic provides detailed explanations that go beyond surface-level knowledge, exploring not just how Kotlin features work but why they were designed that way.
๐กPro Tips for Mastery
The Pro Tips sections dive deeper into advanced topics, uncovering internal structures of Kotlin fundamentals, and offering expert insights for immediate application.
๐References to Source Code
Find references to KEEP proposals, JetBrains YouTrack discussions, and compiler source code, giving direct insight into design decisions.
๐Comprehensive Coverage
From Language Fundamentals to Standard Library, Coroutines, Compiler and Plugins, and Kotlin Multiplatform โ practical knowledge that makes a real difference.
Content Structure
What's Inside This Book
Six comprehensive chapters covering every aspect of Kotlin development
Kotlin Language
Covers Kotlin's foundational building blocks, from null safety and type system design to advanced features like sealed classes, inline functions, and delegation.
Kotlin Standard Library
Deep exploration of Kotlin's rich standard library, including collections, sequences, scope functions, and utilities that make Kotlin code expressive and concise.
Coroutines
Comprehensive exploration of Kotlin's approach to asynchronous programming. From suspending functions and coroutine builders to structured concurrency, Flow, and exception handling.
KotlinX Libraries
Explore official Kotlin libraries developed by JetBrains that extend the language with additional functionality including serialization, date/time, and immutable collections.
Kotlin Compiler & Plugins
Takes you under the hood of how Kotlin code transforms into executable programs. Learn compiler architecture, K2 compiler, FIR, IR, and how to create compiler plugins.
Kotlin Multiplatform
Explore Kotlin's cross-platform capabilities, covering project structure, source set hierarchy, platform interoperability, and Compose Multiplatform for shared UI development.
Testimonials
What Developers Say
Hear from industry experts and GDEs who have read the book
โSince Kotlin was designated as the official language for Android development, it has been loved by many developers and has grown beyond the Android platform. This book is written precisely for these developers. It dives deep into the core principles and internal mechanisms of Kotlin. If you're a Kotlin developer who truly wants to understand the language and elevate your skills to the next level, I highly recommend reading this book.โ
โPractical Kotlin Deep Dive is an exceptionally comprehensive guide that goes beyond syntax to explore the internal mechanisms and design philosophy of the Kotlin language. What makes it stand out is Jaewoong's unique perspective as both a GDE and a prolific open-source contributor โ he brings battle-tested, practical advice that bridges theory and real-world application.โ
โExceptionally well written, breaking down complex concepts into clear and understandable explanations. In an era where AI tools are readily available, this book stands out and is worth every cent. It offers a depth and clarity that you won't easily find elsewhere.โ
โKotlin has evolved from a simple programming language into the core of multiplatform development. This book goes far beyond basic usage to dive deep into the design philosophy and internal mechanisms of Kotlin. It is a must-read for any engineer who wants to truly grasp the core of Kotlin.โ
Reviews
Community Feedback
See what the Kotlin community is saying about the book
Preview
Book Preview
Take a look at the content before you buy
Preview the BookLike what you see? You can read more here:
Global Reach
Available in Multiple Languages
Translated editions for the global Kotlin developer community
Sponsors
Proudly Supported By
Special thanks to our sponsors who support this project
Kotlin Weekly
A weekly newsletter with the best Kotlin articles, libraries, videos, and news delivered directly to your inbox every week.
CodeRabbit is an AI-powered code review platform that integrates directly into pull-request workflows and IDEs, examining code changes and suggesting improvements.
๐ Want to Join?
Interested in sponsoring this book and reaching thousands of Kotlin developers?
skydoves2@gmail.comNow Available in Print
Hardcover & Paperback Edition
Premium quality print with a beautiful dust jacket design
Get on AmazonPractical Kotlin Deep Dive
Master Kotlin with Kotlin Deep Dive Course
An online course unpacking the fundamentals and internal mechanisms of Kotlin programming with coding exercises and quizzes to reinforce concepts.
Table of Contents
70 Deep-Dive Topics
Six comprehensive chapters covering every aspect of Kotlin development
- 1Chapter Overview
- 2The Type System
- 3Null Safety in Kotlin
- 4The Core Principle: A Tale of Two Types
- 5Safely Working with Nullable Types
- 6Interoperability with Java and Platform Types
- 7The Any, Unit, and Nothing Types
- 8Structural and Referential Equality
- 9๐ก Pro Tips for Mastery: How does structural equality (==) work internally?
- 10Code Playground
- 11Properties and Visibility
- 12Variables: var vs val
- 13๐ก Pro Tips for Mastery: Why is the val variable and property read-only and not immutable?
- 14Visibility Modifiers
- 15๐ก Pro Tips for Mastery: How internal visibility modifier is compiled to Java Bytecode?
- 16The init Block
- 17๐ก Pro Tips for Mastery: What are the downsides of init block?
- 18๐ก Pro Tips for Mastery: How init block is compiled to Java Bytecode?
- 19Backing Fields and Backing Properties
- 20Code Playground
- 21Data and Sealed Classes
- 22Data Classes
- 23๐ก Pro Tips for Mastery: Data class inheritance
- 24๐ก Pro Tips for Mastery: The visibility of the copy function of data classes
- 25๐ก Pro Tips for Mastery: Unveiling a data class in Java Bytecode
- 26Sealed Classes
- 27๐ก Pro Tips for Mastery: Sealed class inheritance
- 28๐ก Pro Tips for Mastery: What are the differences between sealed classes and sealed interfaces?
- 29Code Playground
- 30Enum and Value Classes
- 31Enum Classes
- 32๐ก Pro Tips for Mastery: Generic values() and valueOf() for enums
- 33๐ก Pro Tips for Mastery: Decommission Enum.values() and replace it with Enum.entries
- 34๐ก Pro Tips for Mastery: What are the differences between a sealed class and an enum class?
- 35Value Classes
- 36๐ก Pro Tips for Mastery: What are the differences between value classes and inline classes?
- 37๐ก Pro Tips for Mastery: How value class is compiled to Java Bytecode
- 38๐ก Pro Tips for Mastery: @JvmExposeBoxed - Bringing Kotlin's value classes for Java
- 39Code Playground
- 40Objects and Companions
- 41Inner and Nested Classes
- 42Object Declarations
- 43๐ก Pro Tips for Mastery: Object declarations vs. expressions
- 44๐ก Pro Tips for Mastery: What is a data object?
- 45๐ก Pro Tips for Mastery: How Kotlin's object is compiled to Java Bytecode
- 46Companion Objects
- 47Code Playground
- 48Delegation Patterns
- 49Delegated Properties
- 50๐ก Pro Tips for Mastery: Internal mechanisms of Lazy
- 51๐ก Pro Tips for Mastery: How lazy() delegate property is compiled to Java Bytecode?
- 52Lazy Initialization vs lateinit
- 53๐ก Pro Tips for Mastery: How can you check if a lateinit property has been initialized?
- 54๐ก Pro Tips for Mastery: How lateinit is compiled to Java Bytecode
- 55Code Playground
- 56Functions and Lambdas
- 57Higher-Order Functions
- 58๐ก Pro Tips for Mastery: How are higher-order functions compiled into Java bytecode?
- 59Lambda Expressions
- 60Code Playground
- 61Inline and Reified
- 62๐ก Pro Tips for Mastery: What is an inline property?
- 63๐ก Pro Tips for Mastery: How do functions like repeat(), map(), and filter() accept suspending functions?
- 64The reified Keyword
- 65๐ก Pro Tips for Mastery: How inline and reified functions are compiled to Java Bytecode
- 66Functional (SAM) Interfaces
- 67๐ก Pro Tips for Mastery: A philosophy of SAM conversion
- 68Code Playground
- 69Extensions and DSL
- 70Extension Functions
- 71๐ก Pro Tips for Mastery: How are Kotlin extension functions compiled into Java bytecode?
- 72๐ก Pro Tips for Mastery: JvmSynthetic annotation
- 73Domain-Specific Languages (DSL)
- 74Code Playground
- 75Chapter 0 Recap
- 76[Quiz] Kotlin Language
- 77[Advanced Quiz] Kotlin Language
- 1Chapter Overview
- 2Collections and Transformations
- 3Collection Types
- 4Read-Only Collection Types
- 5Mutable Collection Types
- 6๐ก Pro Tips for Mastery: What are the differences between listOf() and emptyList()?
- 7Transformation Operators
- 8map and mapIndexed
- 9flatMap and flatten
- 10groupBy and associateBy
- 11zip and unzip
- 12filter, filterNot, and filterIndexed
- 13Code Playground
- 14Iterators and Sequences
- 15Iterators
- 16MutableIterator
- 17Sequences
- 18Code Playground
- 19Collection Retrieval
- 20Retrieving Parts of Collections
- 21Code Playground
- 22Ordering and Sorting
- 23Code Playground
- 24Scope Functions
- 25let, run, with, apply, also
- 26Choosing the Right Scope Function
- 27Code Playground
- 28Chapter 1 Recap
- 29[Quiz] Standard Library
- 30[Advanced Quiz] Standard Library
- 1Chapter Overview
- 2Coroutines Basics
- 3How Coroutines Work
- 4Launching Coroutines
- 5Suspending Functions
- 6๐ก Pro Tips for Mastery: Coroutines Terminology
- 7Continuation
- 8How Kotlin Compiler Transforms Suspend Functions
- 9Coroutines vs Threads
- 10๐ก Pro Tips for Mastery: What are the differences between multi-threading and multi-processing?
- 11๐ก Pro Tips for Mastery: Coroutine Execution and Mutable State Management
- 12Code Playground
- 13Coroutine Builders
- 14launch, async, runBlocking, produce, actor
- 15๐ก Pro Tips for Mastery: What are the differences between launch and async?
- 16๐ก Pro Tips for Mastery: Why should you use runBlocking with caution?
- 17๐ก Pro Tips for Mastery: Internal mechanisms of the AbstractCoroutine
- 18Code Playground
- 19Coroutine Context and Job
- 20Coroutine Context
- 21๐ก Pro Tips for Mastery: CoroutineContext interface
- 22Job
- 23๐ก Pro Tips for Mastery: What's a SupervisorJob?
- 24Code Playground
- 25Coroutine Scope
- 26GlobalScope, MainScope, viewModelScope, lifecycleScope
- 27๐ก Pro Tips for Mastery: Why should you use GlobalScope carefully?
- 28๐ก Pro Tips for Mastery: What is the coroutineScope() function?
- 29๐ก Pro Tips for Mastery: What is the supervisorScope() function?
- 30Code Playground
- 31Dispatchers and Channels
- 32CoroutineDispatcher
- 33๐ก Pro Tips for Mastery: Differences between CPU-intensive tasks and I/O tasks
- 34๐ก Pro Tips for Mastery: Internals of Dispatchers
- 35Channels
- 36๐ก Pro Tips for Mastery: Internals Mechanisms of Channel
- 37Code Playground
- 38Coroutine Control and Exception Handling
- 39join() and yield() functions
- 40Exception handling in coroutines
- 41๐ก Pro Tips for Mastery: The special nature of CancellationException
- 42๐ก Pro Tips for Mastery: Handling exception propagation when using async
- 43Code Playground
- 44Flow Basics
- 45Cold flow vs Hot flow
- 46๐ก Pro Tips for Mastery: Internal mechanisms of Flow and AbstractFlow
- 47StateFlow and SharedFlow
- 48๐ก Pro Tips for Mastery: Internal Mechanisms of StateFlow
- 49๐ก Pro Tips for Mastery: Internal Mechanisms of SharedFlow
- 50Code Playground
- 51Flow Operators
- 52flowOn, buffer operators
- 53๐ก Pro Tips for Mastery: Internal Mechanisms of flowOn
- 54๐ก Pro Tips for Mastery: Internal Mechanisms of Flow.buffer()
- 55FusibleFlow and ChannelFlow optimization
- 56Code Playground
- 57Flow Transformations
- 58launchIn vs Scope.launch
- 59flatMapLatest, flatMapMerge, flatMapConcat
- 60callbackFlow and channelFlow
- 61Code Playground
- 62Chapter 2 Recap
- 63[Quiz] Coroutines
- 64[Advanced Quiz] Coroutines
- 1Chapter Overview
- 2KotlinX Essentials
- 3Kotlinx Serialization
- 4How Serialization Works
- 5Customizing Serialization
- 6JSON Configuration
- 7Polymorphic Serialization
- 8Multiplatform Support
- 9Kotlinx Datetime
- 10Working with Time Zones
- 11Date Arithmetic
- 12Duration and Period
- 13Parsing and Formatting
- 14Kotlinx Collections Immutable
- 15Truly Immutable Collections
- 16Persistent Collections
- 17Builders for Efficient Bulk Operations
- 18Other Notable KotlinX Libraries
- 19kotlinx-atomicfu
- 20kotlinx-io
- 21kotlinx-benchmark
- 22Dokka
- 23kotlinx-rpc
- 24Kover
- 25Code Playground
- 26Chapter 3 Recap
- 27[Quiz] KotlinX Libraries
- 28[Advanced Quiz] KotlinX Libraries
- 1Chapter Overview
- 2Annotation Processing
- 3Annotation Processors, KAPT, and KSP
- 4Performance Comparison
- 5Migration from KAPT to KSP
- 6Kotlin Compiler Architecture
- 7Structure of the Kotlin Compiler
- 8High-Level Architecture
- 9Frontend and Backend
- 10The Role of IR
- 11The K2 Compiler
- 12Why K2?
- 13Key Improvements
- 14FIR Compilation Phases
- 15K2 for Plugin Authors
- 16Migration to K2
- 17Frontend Intermediate Representation (FIR)
- 18FIR in the K2 Compiler
- 19FIR Element Hierarchy
- 20FIR Resolution Phases
- 21Working with FIR: Symbols and Providers
- 22ConeKotlinType: The Type System
- 23Intermediate Representation and Backends
- 24IR and the Kotlin Backend
- 25IR Tree Structure
- 26Key IR Element Types
- 27IR Lowering: High-Level to Low-Level
- 28Platform-Specific Backends
- 29Writing Kotlin Compiler Plugins
- 30Plugin Architecture Overview
- 31Step-by-step: Define Annotation, Command Line Processor, Component Registrar
- 32Implement K2 FIR Extension
- 33Implement IR Generation Extension
- 34Create Gradle Plugin
- 35Real-World Compiler Plugin Examples
- 36Kotlinx Serialization Plugin
- 37Jetpack Compose Plugin
- 38Parcelize Plugin
- 39All-Open and No-Arg Plugins
- 40Chapter 4 Recap
- 41[Quiz] Compiler Plugins
- 42[Advanced Quiz] Compiler Plugins
- 1Chapter Overview
- 2KMP Fundamentals
- 3Kotlin Multiplatform Overview
- 4Key Features and Advantages
- 5Kotlin Multiplatform Architecture
- 6Expect and Actual Declarations
- 7What Can Be Expected/Actual
- 8Default Implementations
- 9Compiler Guarantees
- 10Concurrency and Asynchronous Programming
- 11Kotlin Coroutines: The Primary Solution
- 12Platform-Specific Dispatchers
- 13Structured Concurrency in Multiplatform
- 14HTTP Network Communication
- 15Ktor Client
- 16Platform-Specific Engines
- 17Ktorfit
- 18Compose Multiplatform
- 19How Compose Multiplatform Works
- 20Writing Shared UI
- 21Supported Platforms and Stability
- 22Resources and Platform Integration
- 23Navigation and Architecture
- 24Source Set Structure
- 25Source Sets in Kotlin Multiplatform
- 26Default Source Set Hierarchy
- 27Intermediate Source Sets
- 28Dependencies Per Source Set
- 29Kotlin/Native
- 30Memory Management
- 31Interoperability with Objective-C and Swift
- 32Coroutines and Swift Async/Await
- 33Performance Considerations
- 34Testing Strategies
- 35Common Test Structure
- 36Testing Coroutines
- 37Platform-Specific Tests
- 38Integration Testing
- 39Dependency Injection Strategies
- 40Metro: Compile-Time DI
- 41Koin: KSP-Based Compile-Time DI
- 42Kodein-DI: Flexible Runtime Container
- 43Manual Dependency Injection
- 44Chapter 5 Recap
- 45[Quiz] Kotlin Multiplatform
- 46[Advanced Quiz] Kotlin Multiplatform
Journey
Timeline & Milestones
Key moments from the book's journey

