Kotlin programming language with Android


  • Kotlin is a statically-typed programming language that runs on the Java virtual machine and also can be compiled to JavaScript source code or use the LLVM compiler infrastructure.
  • Its primary development is from a team of JetBrains programmers based in Saint Petersburg, Russia. 
  • While the syntax is not 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.
  • As of Android Studio 3.0 (Beta version) Kotlin is a fully supported programming language on Android and lets the user choose between targeting Java 6- or Java 8-compatible bytecode.
  • 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.
  • At Google I/O 2017, Google announced first-class support for Kotlin on Android.
  • Kotlin v1.2 was released on November 28, 2017. Sharing Code between JVM and Javascript platforms feature was newly added to this release.

Syntax:

  • Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator), similar to Pascal.
  • As in Scala and Apache 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 and type inference is also supported.

Hello, world! example

1 fun main(args: Array<String>) 
2 {
3       val scope = "world"
4       println("Hello, $scope!")
5 }