start

fun main() {
    println("Hello, world!")
}

That is the smallest program No class wrapper, no public static void The entry point is a function

Why it looks different

Kotlin runs on the JVM It compiles to the same bytecode as Java The syntax is different because the language was designed after years of Java verbosity

val and var

val name = "0x1RIS"
var port = 443
port = 8443

val is read only after assignment var is mutable The tour recommends val by default

String templates

val name = "Mary"
val age = 20
println("$name is $age years old")

Output:

Mary is 20 years old

The $ evaluates the variable Curly braces handle expressions That is cleaner than string concatenation

Types inferred

Kotlin infers Int for 20 and String for "Mary" You can annotate explicitly when the type is not obvious

Next

Variables and types in 02 variables and types

Test this in your lab first

Posted