Kotlin Academy · Lesson

Kotlin Basic Types: Int, Double, Boolean, Char

Learn the primitive-equivalent types in Kotlin and how type inference works.

Lesson 3 of 413 steps

Kotlin Basic Types: Int, Double, Boolean, Char is a free Kotlin Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, and your progress syncs across the web and the CoddyKit app. The Kotlin Academy course includes 4 lessons in total.

Kotlin's Type System

In Kotlin, everything is an object — there are no primitive types in the language spec. But the compiler uses JVM primitives under the hood for performance.

Integer Types

Kotlin provides Byte (8-bit), Short (16-bit), Int (32-bit), and Long (64-bit). Int is the default for integer literals.
val age: Int = 25
val population: Long = 8_000_000_000L
val score: Short = 100
val flags: Byte = 0b00001111

Floating-Point Types

Float (32-bit) and Double (64-bit) handle decimal numbers. Double is the default. Use f suffix for Float literals.
val pi: Double = 3.14159
val gravity: Float = 9.81f
val result = pi * 2  // Double arithmetic

Boolean Type

Boolean holds true or false. Kotlin Boolean is not interchangeable with Int like in C — it's strictly boolean.
val isOnline: Boolean = true
val isEmpty = false
println(!isOnline)           // false
println(isOnline && !isEmpty) // true

Char Type

Char represents a single Unicode character using single quotes. It's distinct from String.
val letter: Char = 'A'
val digit: Char = '7'
val emoji: Char = '\u2764'  // heart
println(letter.code)         // 65 (ASCII)

Type Inference in Action

You rarely need to write the type explicitly. Kotlin infers it from the literal: integer → Int, decimal → Double, true/false → Boolean.
val count = 10        // Int
val ratio = 0.75      // Double
val active = true     // Boolean
val initial = 'K'     // Char

Numeric Underscores for Readability

Large numbers can use underscores to separate digit groups. This is purely visual — no effect on the value.
val million = 1_000_000
val hex = 0xFF_AA_BB
val binary = 0b1010_1010
println(million) // 1000000

Number Conversion

Kotlin does NOT auto-convert between numeric types. You must call explicit conversion functions like toInt(), toLong(), toDouble().
val x: Int = 42
val y: Long = x.toLong()    // explicit
val z: Double = x.toDouble()
println("$y $z")

String Is Not a Primitive

String is a full class in Kotlin with many useful methods. It's immutable and can hold any Unicode text.
val name: String = "Kotlin"
println(name.length)         // 6
println(name.uppercase())    // KOTLIN
println(name[0])             // K (Char)

Any, Nothing, Unit

Any is the root type (like Object in Java). Unit is the return type for functions that return nothing (like void). Nothing is the type of expressions that never complete.
fun greet(): Unit { println("Hi") }
fun fail(): Nothing { throw Exception("!!") }
val x: Any = 42  // Any accepts anything

Checking Types with is

Use the is operator to check a value's type at runtime. After a check, Kotlin smart-casts the variable automatically.
val obj: Any = "Hello"
if (obj is String) {
    println(obj.length) // smart cast: no cast needed!
}

Quick Check

What is the default type inferred for the literal 3.14 in Kotlin?

Recap

Kotlin types: Int, Long, Float, Double, Boolean, Char, String, Any, Unit. No auto-conversion between numbers — use .toX() functions. Smart casts make type-safe code concise!
Free to start

Learn Kotlin with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “Kotlin Basic Types: Int, Double, Boolean, Char” lesson free?

Yes — any 3 lessons of the Kotlin Academy learning path, including “Kotlin Basic Types: Int, Double, Boolean, Char”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Kotlin Academy course includes 4 lessons in total.

What will I learn in “Kotlin Basic Types: Int, Double, Boolean, Char”?

Learn the primitive-equivalent types in Kotlin and how type inference works. You practise Kotlin Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Academy?

No prior experience is required. Kotlin Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Kotlin Basic Types: Int, Double, Boolean, Char” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Academy lesson?

Yes. Every Kotlin Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Setting Up Kotlin: REPL, IntelliJ & Online Playground
  2. val vs var: Immutability From Day One
  3. Kotlin Basic Types: Int, Double, Boolean, Char
  4. Your First Kotlin Program: main, println & Input
← Back to Kotlin Academy