๐ŸŽ“ A1Learner
๐Ÿ”

Kotlin Get Started

Getting started with Kotlin is writing a program file, compiling it, and running the compiled program.

A one statement file

This file holds one statement inside main. The statement shows one line.

fun main() {
    println("Ready")
}

Statements in order

Step one appears above Step two in the output. The order on screen matches the order in the file.

fun main() {
    println("Step one")
    println("Step two")
}

A short first run

This file holds two statements. Each statement shows its own line.

fun main() {
    println("My program")
    println("It works")
}

Example

fun main() {
    println("Program starts")
    println("Program ends")
}

Key points

  • The program file in this course is main.kt.
  • JVM: a program that runs compiled code on a computer.
  • Use kotlinc main.kt -include-runtime -d main.jar to compile the file into main.jar.
  • Use java -jar main.jar to run main.jar on the JVM.
  • A statement is one complete instruction in a program.
  • Statements run from top to bottom.

In this example, the first statement shows Program starts. The second statement shows Program ends below the first line.

Try it Yourself

Edit the code, then press Run.

Running is simulated ยท Kotlin Playground

Exercise

Which command compiles the file main.kt?