Designed by JetBrains Typing discipline static, inferred | First appeared 2011 | |
![]() | ||
Developer JetBrains and open source contributors Stable release Kotlin 1.1.0 / March 1, 2017; 14 days ago (2017-03-01) Preview release Kotlin 1.1.0-rc-91 / February 17, 2017; 26 days ago (2017-02-17) |
Kotlin is a statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code. Its primary development is from a team of JetBrains programmers based in Saint Petersburg, Russia (the name comes from the Kotlin Island, near St. Petersburg). Kotlin was named Language of the Month in the January 2012 issue of Dr. Dobb's Journal. While not syntax compatible with Java, Kotlin is designed to interoperate with Java code and is reliant on Java code from the existing Java Class Library, such as the collections framework.
Contents
History
In July 2011 JetBrains unveiled Project Kotlin, a new language for the JVM, which had been under development for a year. JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for, with the exception of Scala. However, he cited the slow compile time of Scala as an obvious deficiency. One of the stated goals of Kotlin is to compile as quickly as Java. In February 2012, JetBrains open sourced the project under the Apache 2 license. Jetbrains hopes that the new language will drive IntelliJ IDEA sales.
Kotlin v1.0 was released on February 15, 2016. This is considered to be the first officially stable release and JetBrains has committed to long-term backwards compatibility starting with this version.
Philosophy
Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength object-oriented language, and a "better language" than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.
Syntax
Like Pascal, TypeScript, Haxe, PL/SQL, F#, Go, Rust and Scala—and unlike C and its derivatives such as C++, Java, C#, and D—Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator). As in Scala and Groovy, semicolons are optional as a statement terminator; in most cases a newline is sufficient for the compiler to deduce that the statement has ended.
Semantics
In addition to the classes and methods (called member functions in Kotlin) of object-oriented programming, Kotlin also supports procedural programming with the use of functions. As in C and C++, the entry point to a Kotlin program is a function named "main", which is passed an array containing any command line arguments. Perl and Unix/Linux shell script-style string interpolation is supported. Type inference is also supported.
Hello, world! example
Kotlin makes a distinction between nullable and non-nullable datatypes. All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects need special care from developers: null-check must be performed before using the value. Kotlin provides null-safe operators to help developers:
An example of the use of the safe navigation operator:
Tools
Applications
One of the obvious applications of Kotlin is Android development. The platform has been long stuck on Java 6 (note: retrolambda and the transition to Jack compiler) and Kotlin introduces many improvements for programmers such as null-pointer safety, extension functions and infix notation. Accompanied by full Java compatibility and good IDE support (Android Studio) it is intended to improve code readability, give an easier way to extend Android SDK classes and speed up development.
Users
According to the Kotlin website, Tuenti and Prezi are using Kotlin in the backend. DripStat has done a writeup of their experience with Kotlin.