Kotlin (programming language)
Designed by | JetBrains |
---|---|
Developer | JetBrains and open source contributors |
Stable release | Kotlin 1.0.1 / March 16, 2016 |
Preview release | Kotlin 1.0.2 EAP 44 / April 16, 2016[1] |
Typing discipline | static |
Platform | Outputs Java Virtual Machine bytecode and JavaScript source code |
OS | any supporting a JVM or JavaScript interpreter |
License | Apache 2 |
Filename extensions | .kt, .kts |
Website | kotlinlang |
Influenced by | |
Java, Scala, Groovy, C#, Gosu |
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).[2] Kotlin was named Language of the Month in the January 2012 issue of Dr. Dobb's Journal.[3] 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.[4] 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.[4] 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.[5] Jetbrains hopes that the new language will drive IntelliJ IDEA sales.[6]
Kotlin v1.0 was released on February 15, 2016.[7] 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 to be a better language than Java but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.[8]
Syntax
Like Pascal, TypeScript, Haxe, PL/SQL, F#, Go 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 other modern languages such as 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.[9]
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.[10] 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
fun main(args : Array<String>) {
val scope = "world"
println("Hello, $scope!")
}
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:
- ?. (safe navigation operator) can be used to safely access a method or property of a possibly null object. If the object is null, the method will not be called and the expression evaluates to null.
- ?: (null coalescing operator) often referred to as the Elvis operator:
fun sayHello(maybe : String?, neverNull : Int) {
// use of elvis operator
val name : String = maybe ?: "stranger"
println("Hello $name")
}
An example of the use of the safe navigation operator:
// returns null if foo is null, or bar() returns null, or baz() returns null
foo ?. bar() ?. baz()
Tools
- IntelliJ IDEA has plug-in support for Kotlin.[11] IntelliJ IDEA 15 is the first version to bundle Kotlin plugin in the IntelliJ Installer, and provide support of it out of the box.[12]
- JetBrains also has an Eclipse plug-in.[13]
- Apache Maven plugin.[14]
- Apache Ant task.[14]
- Gradle plugin.[14]
See also
There are other languages intended to be a better language than Java for the JVM:[15]
- Ceylon (programming language)
- Clojure
- Fantom (programming language)
- Gosu (programming language)
- Scala (programming language)
- Groovy (programming language)
- Xtend
Related concepts:
Applications
One of the obvious applications of Kotlin is Android development. The platform has been long stuck on Java 6 (note: retrolambda[16] and the transition to Jack compiler[17]) and Kotlin introduces many improvements for programmers such as null-pointer safety, extension functions and infix notation. Accompanied by 100% Java compatibility and good IDE support (Android Studio[18]) it gives an excellent way to improve code readability, extend Android SDK classes and speed up development.
Users
According to the Kotlin website, Prezi is using Kotlin in the backend.[19]
References
<templatestyles src="Reflist/styles.css" />
Cite error: Invalid <references>
tag; parameter "group" is allowed only.
<references />
, or <references group="..." />
External links
- No URL found. Please specify a URL here or add one to Wikidata.
- Web-Demo and examples
- ↑ https://discuss.kotlinlang.org/t/kotlin-1-0-2-eap/1581/2
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ 4.0 4.1 Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ https://www.jetbrains.com/idea/whatsnew/
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ 14.0 14.1 14.2 Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Kotlin and the search for a better Java, Stephen Colebourne, 2011-07-21.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- Pages with syntax highlighting errors
- Pages with reference errors
- Official website missing URL
- Java platform
- Java programming language family
- JVM programming languages
- Object-oriented programming languages
- Programming languages created in 2011
- Programming languages
- Software using the Apache license
- Statically typed programming languages