Skip to main content

Syntax for Kotlins

Kotlin syntax is the set of rules for declaring variables, types and functions, including the type system that separates nullable from non-null values. It sits at the base of the language and every later topic builds on it, from val and var declarations to default arguments and expression bodies.

Stage: Language · Part of the Kotlin roadmap · Last reviewed 19 November 2026

What to learn in Syntax

Syntax interview questions

How does Kotlin prevent NullPointerException?

The type system distinguishes String from String?. A non-null type cannot hold null, and the compiler forces you to handle nullable values using safe calls, the Elvis operator or explicit checks. Exceptions can still come from the !! operator or from Java code with unknown nullability.

What is the difference between val and var in Kotlin?

val declares a read-only reference that can be assigned once, while var declares a reference that can be reassigned. A val is not necessarily immutable, because the object it points to may still be mutable, for example a MutableList.

Where Syntax fits in the Kotlin roadmap

Syntax belongs to the Language stage (beginner level), which takes about 22 hours. Kotlin basics.

Back to the full Kotlin roadmap