Kotlin for Android 5 lessons
  1. 1 Kotlin in an afternoon
  2. 2 How an Android app is put together sign in to open
  3. 3 Building a screen with Compose sign in to open
  4. 4 Data, networking and storage sign in to open
  5. 5 Shipping it sign in to open
Course overview
Data: video · change

This lesson: 122KB

Kotlin for Android · Lesson 1 of 5

Kotlin in an afternoon

Read and write the language Android now uses.

Kotlin is the official language for Android, and if you know any Java or JavaScript you can read it within a day.

Three features carry most of the difference.

Null safety in the type system. A String cannot hold null. A String with a question mark after it can. The compiler will not let you use the second without handling the null case, which removes the single most common crash in Android history. The safe call operator returns null instead of throwing, and the elvis operator supplies a default. Learn those two symbols and most null handling becomes one line.

val and var. val is a value that cannot be reassigned, var can. Use val by default and change it only when you must. Most variables never need to change, and saying so makes code easier to reason about.

Data classes. One line gives you a class with equality, a readable toString and a copy method. Most of the boilerplate that made Java tedious disappears here.

Beyond those, functions can be declared at the top level without a class, string templates put a value inside a string directly, and when replaces switch and is far more capable.

Coroutines handle work that takes time, which on Android means every network call and every database read. The rule is simple: never block the main thread. A frozen interface is what users call a broken app, and Android will show them a dialog saying so.

Lab — try it yourself

Write a data class, create two instances with the same values, and check whether they are equal. Then make one field nullable and handle it with the elvis operator.

Check what you learned

Create your free BvLogic ID to take the quiz and record your score.

Create your BvLogic ID
Continue to lesson 2 Up next 2. How an Android app is put together