Thuta Learning
BasicProgrammingbeginner

Data Types

Relax. We'll talk through this in plain words — no textbook voice.

Since Kotlin is a statically typed language, the compiler always knows what data type a variable stores. You can write the type yourself, or let Kotlin figure it out automatically from the value. This feature is called type inference.

kotlin
fun main() {
    val age: Int = 25
    val price: Double = 19.99
    val grade: Char = 'A'
    val isActive: Boolean = true
    val title: String = "Kotlin Basics"

    println("$title - age limit: $age")
    println("Price: $price")
    println("Grade: $grade")
    println("Active: $isActive")
}
You should see
Kotlin Basics - age limit: 25 Price: 19.99 Grade: A Active: true

Summary

Understanding data types means storing values in the right shape, which cuts down on errors.

Easy traps

  • Writing val grade: Char = "A" with double quotes turns it into a String, which causes a type mismatch.