ProgramGuru

What is Kotlin?

What is Kotlin?

A school report needs names, calculations and clear decisions. Kotlin is a programming language for describing those operations. It supports several targets, but this course uses Kotlin/JVM: the compiler produces code that runs on the Java Virtual Machine. You do not need previous Java knowledge to begin.

Your source file contains instructions written in Kotlin. The compiler checks language rules and generates JVM bytecode. Running the compiled program performs the instructions. Kotlin is the language, while Android, server frameworks and interface libraries add their own application environments.

What you’ll learn

  • Distinguish Kotlin source, JVM bytecode and program output.
  • Separate console code from application frameworks.

What is Kotlin? in the example

  1. Kotlin source

    A school report needs names, calculations and clear decisions.

    Kotlin source
  2. JVM bytecode

    Your source file contains instructions written in Kotlin.

    JVM bytecode
  3. Console result

    The JVM application starts at main.

    Console result
The JVM application starts at main. Val gives the school text a name, and println displays that value followed by a newline. No Android activity or interface framework is involved in this console result.

Follow what is kotlin?

Save the complete source as Main.kt and use the Kotlin/JVM environment. No separate input file is needed.

Kotlin/JVM · complete program

fun main() {
  val school = "River School"
  println(school)
}

Expected output

River School

Follow the execution

The JVM application starts at main. Val gives the school text a name, and println displays that value followed by a newline. No Android activity or interface framework is involved in this console result.

Try this in the Kotlin compiler by pasting the complete program.

Practice: What is Kotlin?

Your task: Would changing the school text require rewriting println?

Kotlin/JVM · complete program

fun main() {
  val school = "River School"
  println(school)
}

Worked answer

No. Change the value assigned to school; println reads that named value. Separating data from the operation makes the change easy to inspect.

What is Kotlin?: the important boundary

Compilation catches many source mistakes, but it does not prove that the report rules are correct. Kotlin/JVM examples do not automatically describe Kotlin/Native or JavaScript platform APIs. We will name JVM-specific operations when using them.

Check your understanding

Would changing the school text require rewriting println?
Choose one answer. You can try again.

Answer and explanation

No.

No. Change the value assigned to school; println reads that named value. Separating data from the operation makes the change easy to inspect.

What is Kotlin?: what to keep in mind

No. Change the value assigned to school; println reads that named value. Separating data from the operation makes the change easy to inspect. Compilation catches many source mistakes, but it does not prove that the report rules are correct.

Further reading: official Kotlin documentation for this topic.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Set up Kotlin and the JVM →