Kotlin is a general-purpose cross-platform programming language developed by JetBrains to be fully interoperable with Java. The Kotlin source code is contained in a file with the .kt extension. The Kotlin trademark is protected by the Kotlin Foundation.
Kotlin was announced as the preferred programming language for Android App development by Google on 7th May 2019. Android Studio 3.0 started supporting Kotlin as an alternative for Android App development in October 2017.
Kotlin was unveiled by JetBrains in July 2011 as a new programming language for JVM. The lead of JetBrains Dmitry Jemerov said that most of the languages were missing features that they were looking for except Scala but the slow compilation of Scala was a drawback. One of the main goals of Kotlin was to compile as quickly as Java. The Kotlin project was open-sourced under Apache 2 License in February 2012.
Kotlin was designed to be better than Java but still be interoperable with Java code to allow gradual migration from Java to Kotlin.
Semicolons are optional in Kotlin. A new line is enough to indicate the end of the statement.
Kotlin supports two types of variables, read-only, defined by the val keyword, and mutable, defined by the var keyword.
Classes are private and final by default. To derive from a class, the base class has to be declared with the open keyword.
Kotlin also supports procedural programming.
The entry point to the Kotlin program is the “main” function similar to Java, C#, etc.
The following is an example of Kotlin syntax.
// The example code prints Hello World from Kotlin to the console.
In the above code, the fun keyword defines the function named main. Inside the function, a read-only variable ‘audience’ is declared with the val keyword. By using the println method, “Hello World from Kotlin” is printed on the console. The value of the variable audience is injected into the string with the $ sign.
How to open KT files
Kotlin files can be opened by using the following programs.