This book is for everyone who has at least one year of programming experience and is intended to deliver the basic constructs of a programming language. You do not need any prior experience with Kotlin or Java. Some basic familiarity with Android is helpful for the practical part of this book, but it is not required.
This book also assumes you’re familiar with some basic terms surrounding software development. The glossary can help if you’re unfamiliar with a certain term that is used without explanation.
In short, you fulfill the prerequisites to follow this book if any of the following are true.
You have a year of programming experience.
You’re a Java or Android developer.
You’re a Kotlin developer who wants to use the language to build Android apps.
You have attended an introductory programming class at university.
This is by no means an exhaustive list. Most important, you should be eager to learn Kotlin and then put it into practice by building two Android apps.
This book first covers Kotlin in detail to teach you all essential language features, and then moves on to using Kotlin in the context of Android. Although Kotlin is introduced comprehensively, this is by no means a language reference but rather a practical book focusing on gaining hands-on experience.
Part I, Learning Kotlin, introduces the Kotlin programming language.
Chapter 1, Introducing Kotlin, gives an overview of Kotlin and motivation to learn this language.
Chapter 2, Diving into Kotlin, then covers the basic language constructs such as control flow, functions, and exceptions. It also focuses on the underlying principles of Kotlin and how they are reflected in the language design.
Chapter 3, Functional Programming in Kotlin, shows how Kotlin incorporates functional programming concepts, how you can use them, and what their potential benefits are.
Chapter 4, Object Orientation in Kotlin, deals with object orientation in Kotlin and interesting features the language provides to write reusable and concise code. It also again highlights selected language design decisions.
Chapter 5, Interoperability with Java, discusses common issues, solutions, and best practices for interoperability with Java.
Chapter 6, Concurrency in Kotlin, covers concurrency in Kotlin and is therefore mostly about coroutines, Kotlin’s answer to asynchronous and concurrent programming.
Part II, Kotlin on Android, lets you put what you learned in Part I into practice by building two Android apps with Kotlin.
In Chapter 7, Android App Development with Kotlin: Kudoo App, you will create a simple to-do list app purely in Kotlin while following best practices, such as using Android’s Architecture Components, recycler views, and coroutines.
Chapter 8, Android App Development with Kotlin: Nutrilicious, then guides you through a more complex app that offers nutrition data to users. The data is fetched from a third-party API, mapped to an internal data representation, and then presented to the user. This app introduces more common tools and best practices for Android such as using Retrofit for network calls, splitting up your app into fragments, and using a repository as a single source of truth for data.
Chapter 9, Kotlin DSLs, covers how to create simple domain-specific languages purely in Kotlin by combining its language features in a clever way. These DSLs can improve code readability and reliability.
Chapter 10, Migrating to Kotlin, provides guidance for migrating from Java to Kotlin, including how to evaluate whether Kotlin is a good fit, common obstacles, and practices that have helped other companies adopt Kotlin successfully.
Unless you already have a strong understanding of Kotlin, you should definitely go through Part I before attempting to build the apps in Part II. You may skip Chapter 5, which covers interoperability with Java, but it is useful to understand what happens under the hood and how Kotlin compiles to Java bytecode. Also, even if you already know Kotlin, you may want to read Chapter 6 if you’re not familiar with coroutines yet.
In Part II, you may skip Chapter 9 covering domain-specific languages (DSLs) because it is not a prerequisite for another chapter. However, DSLs are a popular feature of Kotlin that can improve your code, and it’s a good way to recap interesting language features from Part I. Finally, if you’re not interested in migrating an existing app to Kotlin or adopting Kotlin at your company, you may skip Chapter 10.
For all resources, updates, and news related to this book, please visit its companion website at
The site hosts runnable and editable versions of all listings in this book for you to work with, lists all related resources and GitHub repositories, and presents any updates and corrections for the book. In short, it’s your companion while reading this book and applying it to your work. The main GitHub repository for this book can also be found directly at github.com/petersommerhoff/kotlin-for-android-app-development.
This book follows several conventions that are used consistently throughout the book.
Unless stated otherwise, all listings in this book assume they are run as a Kotlin script file (with .kts extension) and therefore don’t use a main function. Chapters 7 and 8 are excluded from this because they assume your code runs on Android.
In Part I, notes marked as “Java Note” are intended for Java developers and typically compare a concept to its Java counterpart. You can safely ignore them if you don’t know Java.
I aimed to use all terms in this book accurately and consistently. If you don’t know a term, it may be covered in the Glossary.
Register your copy of Kotlin for Android App Development on the InformIT site for convenient access to updates and/or corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account. Enter the product ISBN (9780134854199) and click Submit. Look on the Registered Products tab for an Access Bonus Content link next to this product, and follow that link to access any available bonus materials. If you would like to be notified of exclusive offers on new editions and updates, please check the box to receive email from us.