Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types-kotlin

Variables and types

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and types: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Teams still ship Variables and types in Kotlin codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and types in contexts like: Android apps, Spring services, and shared KMP modules.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Kotlin is statically typed like Java and C#. Use val for read-only references and var for mutable ones—both require explicit or inferred types.

Basic types

  • Int, Long, Double — numeric types (capitalized, not Java primitives in source)
  • String — immutable UTF-16 text
  • Booleantrue or false
  • Char — single UTF-16 code unit

val vs var

val count = 10      // read-only reference
var total = 0       // mutable
total += count

val does not make objects immutable—only the variable binding. Prefer val by default.

Important interview questions and answers

  1. Q: val vs var?
    A: val assigns once (like final in Java); var allows reassignment.
  2. Q: Are Kotlin types nullable by default?
    A: No—String cannot hold null unless you write String?.

Self-check

  1. Which keyword declares a read-only variable?
  2. Can you reassign a val?

Pitfall: val does not make objects immutable—only the variable binding; prefer val by default.

Interview prep

val vs var?

val assigns once; var allows reassignment.

Nullable by default?

No—use String? for nullable references.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • val vs var?
  • Type inference when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump