Kotlin (programming language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Kotlin
Kotlin language logo.png
Designed by JetBrains
Developer JetBrains and open source contributors
Typing discipline static
Influenced by Java, Scala, Groovy, C#, Gosu
Platform Outputs Java Virtual Machine bytecode and JavaScript source code
OS any supporting a JVM or JavaScript interpreter
License Apache 2
Filename extension(s) .kt
Website http://kotlinlang.org/

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.

History[edit]

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[edit]

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[edit]

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[edit]

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[edit]

See also[edit]

There are other languages trying to be a better language than Java for the JVM:[12]

Related concepts:

Users[edit]

According to the kotlin website, Prezi is using Kotlin in the backend.[13]

References[edit]

  1. ^ Heiss, Janice (April 2013). "The Advent of Kotlin: A Conversation with JetBrains' Andrey Breslav". oracle.com. Oracle Technology Network. Retrieved February 2, 2014. 
  2. ^ Breslev, Andrey (January 20, 2012). "Language of the Month: Kotlin". drdobbs.com. Retrieved February 2, 2014. 
  3. ^ a b Krill, Paul (Jul 22, 2011). "JetBrains readies JVM language Kotlin". infoworld.com. InfoWorld. Retrieved February 2, 2014. 
  4. ^ Waters, John (February 22, 2012). "Kotlin Goes Open Source". ADTmag.com/. 1105 Enterprise Computing Group. Retrieved February 2, 2014. 
  5. ^ "Why JetBrains needs Kotlin". "we expect Kotlin to drive the sales of IntelliJ IDEA" 
  6. ^ RebelLabs (April 22, 2013). "JVM Languages Report extended interview with Kotlin creator Andrey Breslav". http://zeroturnaround.com/. Retrieved February 2, 2014. 
  7. ^ "Semicolons". jetbrains.com. Retrieved February 8, 2014. 
  8. ^ "functions". jetbrains.com. Retrieved February 8, 2014. 
  9. ^ "Jetbrains Plugin Repository:Kotlin". 
  10. ^ "Kotlin for Eclipse". 
  11. ^ a b c "Kotlin Build Tools". 
  12. ^ Kotlin and the search for a better Java, Stephen Colebourne, 2011-07-21.
  13. ^ "Project Kotlin". "Kotlin in backend, data processing and service development" 

External links[edit]