Kotlin Tutorial

Kotlin is a statically typed programming language that runs on the Java Virtual Machine, known as the Swift of the Android world, designed and open-sourced by JetBrains.

Kotlin can be compiled into Java bytecode, and can also be compiled into JavaScript, making it convenient to run on devices without a JVM.

At Google I/O 2017, Google announced that Kotlin became the official development language for Android.


My First Kotlin Program

Kotlin program files end with.ktsuch as: hello.kt, app.kt.

Simplest Version

package hello //Optional package header fun main(args: Array<String>) { //Package-level visible function, accepting a string array as a parameter println("Hello World!") //Semicolons can be omitted }

Run Example »

Object-Oriented

class Greeter(val name: String) { fun greet() { println("Hello, $name") } } fun main(args: Array<String>) { Greeter("World!").greet() //Creating an object does not require the new keyword }

Run Example »

Why Choose Kotlin?

  • Concise: Greatly reduces the amount of boilerplate code.
  • Safe: Avoids entire classes of errors such as null pointer exceptions.
  • Interoperable: Fully leverages existing libraries for JVM, Android, and browsers.
  • Tool-friendly: Can be built with any Java IDE or using the command line.

Reference Links

Other Extensions