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).[1] Kotlin was named Language of the Month in the January 2012 issue of Dr. Dobb's Journal.[2] 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.
Kotlin | |
---|---|
File:Kotlin language logo.png | |
Designed by | JetBrains |
Developer | JetBrains and open source contributors |
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 |
Website | http://kotlinlang.org/ |
Influenced by | |
Java, Scala, Groovy, C#, Gosu |
History
In July 2011 JetBrains unveiled Project Kotlin, which had been under development for a year, a new language for the JVM.[3] 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.[3] One of the stated goals of Kotlin is to compile as fast as Java. In February 2012, JetBrains open sourced the project under the Apache 2 license.[4] Jetbrains hopes that the new language will drive IntelliJ IDEA sales.[5]
Philosophy
Development lead Andrey Breslav has said that Kotlin is designed to be an industrial strength object-oriented language, 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.[6]
Syntax
Like Pascal, Haxe and Scala, Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator), unlike C and its derivatives such as C++, Java, C#, and D. As in other modern languages like 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.[7]
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.[8] 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 difference between nullable and non-null datatypes. All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects needs 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.
- ?: also known as Elvis operator
fun sayHello(maybe : String?, neverNull : Int)
{
// use of elvis operator
val name : String = maybe ?: "stranger"
println("Hello ${name}")
}
An example for 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.[9]
- JetBrains is also working on an Eclipse plug-in.[10]
- Apache Maven plugin.[11]
- Apache Ant task.[11]
- Gradle plugin.[11]
See also
There are other languages trying to be a better language than Java for the JVM:[12]
Related concepts:
References
- ^ Heiss, Janice (April 2013). "The Advent of Kotlin: A Conversation with JetBrains' Andrey Breslav". oracle.com. Oracle Technology Network. Retrieved February 2, 2014.
- ^ Breslev, Andrey (January 20, 2012). "Language of the Month: Kotlin". drdobbs.com. Retrieved February 2, 2014.
- ^ a b Krill, Paul (Jul 22, 2011). "JetBrains readies JVM language Kotlin". infoworld.com. InfoWorld. Retrieved February 2, 2014.
- ^ Waters, John (February 22, 2012). "Kotlin Goes Open Source". ADTmag.com/. 1105 Enterprise Computing Group. Retrieved February 2, 2014.
- ^ "Why JetBrains needs Kotlin".
we expect Kotlin to drive the sales of IntelliJ IDEA
- ^ RebelLabs (April 22, 2013). "JVM Languages Report extended interview with Kotlin creator Andrey Breslav". http://zeroturnaround.com/. Retrieved February 2, 2014.
{{cite web}}
: External link in
(help)|website=
- ^ "Semicolons". jetbrains.com. Retrieved February 8, 2014.
- ^ "functions". jetbrains.com. Retrieved February 8, 2014.
- ^ "Jetbrains Plugin Repository:Kotlin".
- ^ "Kotlin for Eclipse".
- ^ a b c "Kotlin Build Tools".
- ^ Kotlin and the search for a better Java, Stephen Colebourne, 2011-07-21.