A source code written in Kotlin is saved with .kt extension which is commonly known as Kotlin file extension. The Kotlin is a general-purpose cross-platform programming language developed by JetBrains to be fully interoperable with Java. 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.
Brief History of Kotlin KT File Format##
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.
Kotlin vs Java
The Kotlin is an official language to write Android apps with offering many advanced features, but many expert Java developers still don’t show their interest to switch to Kotlin. They think that they can do all with Java only. So following is the comparison between two technologies which may convince the java developers to switch: