← All courses

Getting Started with Kotlin

🗓 May 31, 2026 ⏱ 3 min read

What is Kotlin?

Kotlin is a modern programming language created by JetBrains (the company behind IntelliJ and Android Studio) and officially recommended by Google for Android. It runs on the Java Virtual Machine (JVM), so it works anywhere Java works — Android apps, servers, desktop tools — and through Kotlin Multiplatform it can even target iOS and the web.

The language was designed to fix Java’s biggest pain points. It is more concise (less boilerplate), safer (it stops most null-pointer crashes at compile time), and 100% interoperable with Java (you can mix both in one project).

Why learn Kotlin first?

If you want to build Android apps, Kotlin is no longer optional — it is the default. Every modern Android library, sample and tutorial assumes Kotlin. Learning the language well before diving into Android means you spend your energy on app concepts instead of fighting syntax.

Where to run it

You don’t need Android to practise Kotlin. The fastest way is the online Kotlin Playground in your browser, or create a Kotlin project in IntelliJ IDEA / Android Studio. Every program starts at the main function:

fun main() {
    val name = "World"
    println("Hello, $name!")   // string templates insert values with $
}

Here fun declares a function, val declares a value, and $name inserts the variable directly into the string — no clumsy concatenation.

Variables: val vs var

Kotlin has two keywords for variables, and choosing the right one is an important habit:

  • val — a read-only value. Once set, it cannot be reassigned. Prefer this.
  • var — a mutable variable that can change.
val pi = 3.14        // type Double, inferred automatically
var count = 0        // mutable
count = count + 1    // ok
// pi = 3.15         // ❌ error: val cannot be reassigned

Basic types

val age: Int = 25
val price: Double = 99.5
val grade: Char = 'A'
val isActive: Boolean = true
val city: String = "Delhi"

Kotlin usually infers the type, so you can drop the explicit type when it’s obvious. Note there are no primitive types to worry about — everything is an object.

Reading input and simple output

fun main() {
    print("Enter your name: ")
    val name = readLine()                 // returns a String? (may be null)
    println("Welcome, ${name ?: "guest"}!")
}

The ${...} syntax lets you put an expression inside a string. ?: (the Elvis operator) provides a fallback if the value is null — you’ll meet it properly in the null-safety lesson.

Comments

// single line
/* multi
   line */
/** Documentation comment for functions and classes */

Common beginner mistakes

  • Using var everywhere — default to val and only switch to var when you truly need to change the value.
  • Concatenating strings with + when templates ($name) are cleaner.
  • Forgetting that readLine() can return null.
Summary: Kotlin is concise, null-safe and Java-compatible. Programs start at main(), prefer val over var, and use string templates with $.