O'Reilly logo
live online training icon Live Online training

Kotlin fundamentals

A quick guide to Kotlin's syntax and semantics

Ken Kousen

Kotlin—an alternative language on the Java Virtual Machine—greatly simplifies programs that would otherwise be written in Java. It's managed by IDE vendor JetBrains, so the tools around it are powerful and mature. Kotlin's extensive use in Android development means the core team has focused on performance, optimizing for both size and speed. Kotlin is also expanding into additional areas, including iOS development, native applications, JavaScript generation, and more.

Ken Kousen walks you through the basic syntax and standard idioms for writing and executing Kotlin programs. You'll learn about installation and execution options, object-oriented and functional programming techniques, basic data types, collections, and more.

What you'll learn-and how you can apply it

By the end of this live, online course, you’ll understand:

  • How to install the Kotlin compiler and execution environments
  • How to decide between nullable and non-nullable types
  • Where to find the provided documentation and how to use it

And you’ll be able to:

  • Read and write basic Kotlin programs
  • Distinguish between classes and object singletons
  • Write functions, classes, and objects in Kotlin
  • Work with collections
  • Use conditional expressions like "if" and "when"
  • Employ basic functional concepts like map, filter, and reduce

This training course is for you because...

  • You're a Java developer who wants to simplify your code while retaining safety as a primary goal.
  • You're planning to do Android development and are familiar with its basic principles.
  • You're an architect trying to decide whether Kotlin should be supported in your organization.

Prerequisites

  • A working knowledge of object-oriented programming concepts, preferably in Java (such as in Java 7 or above)
  • Familiarity with functional concepts like streams, lambdas, and method references (such as in Java 8 or above) (useful but not required)
  • A machine with IntelliJ IDEA (either the free Community edition or the commercial Ultimate edition) or Android Studio installed

About your instructor

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Installing and running Kotlin (30 minutes)

  • Lecture and hands-on exercises: Installation options; cloning the sample repository; command-line tools; using the REPL; compiling and executing Kotlin programs; using build tools like Maven and Gradle; IDE support

Kotlin basics (45 minutes)

  • Lecture and hands-on exercises: Deciding between var and val types; declaring variables to be nullable; defining top-level functions; defining classes and interfaces; creating object singletons; reference equality and object equivalence
  • Break (15 minutes)

Collections and arrays (30 minutes)

  • Lecture and hands-on exercises: Mutable and immutable collections; creating arrays; common collection methods; read-only collections; grouping and associating values

Functional concepts (45 minutes)

  • Lecture and hands-on exercises: Lambda expressions; function references; mapping and filtering; reduction operations; sequences and lazy evaluation
  • Break (15 minutes)

Data classes (30 minutes)

  • Lecture and hands-on exercises: Defining data classes; generated methods; the copy() function; accessing components

Interacting with Java (25 minutes)

  • Lecture and hands-on exercises: Decompiling Kotlin bytecodes; companion objects and static; primitive types and wrapper classes; working with platform types; generating function overloads; changing generated class names

Wrap-up, Q&A, and resources for further learning (5 minutes)