Kotlin Syntax
Kotlin syntax is compact and expression-oriented. The language prefers readability, explicit types when needed, and fewer special cases than older JVM languages.
Declarations
val language = "Kotlin"
var count = 1
println("$language count = $count")
Expressions
Many Kotlin constructs are expressions. That means they produce values instead of only performing actions.
Program shape
fun main() {
println("Hello Kotlin")
}
Syntax rules
- Use
valfor values that should not change. - Use
varonly when reassignment is necessary. - Prefer small functions and explicit names.
Practice
- Write one
mainfunction that prints two lines. - Change one
vartovaland explain the effect. - Write one note about why Kotlin feels cleaner than Java in small programs.