Introduction to Kotlin

Wednesday, June 07, 2017 Unknown 0 Comments


About:
Kotlin is a new programming language by JetBrains, the makers of the world’s best IDES. It  is a statically typed programming language that runs on the java virtual machine and can also be compiled  to  Javascript  source code. It’s primary development is from a team of JetBRains programmers based in Saint Petersberg, Russia.  The name came from Kotlin Island.


History :
In july 2011 JetBrains unveiled project Kotlin, a new programming language for 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 except 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. JetBrains open sourced the projct under Apache 2 license in 2012.
              JetBrains hopes that new programming language will drive IntelliJ IDEA sales.
Kotlin v1.0 was released on February 15,2016. This is considered as the first official stable release. In Google I/O 2017, Google announced first class support for Kotlin on Android.

Syntax :
Kotlin variable declarations and parameter lists have the data type after the variable name like Swift. Semicolon are optional.

Semantics :
In addition to the classes and methods(member functions) of object oriented programming, Kotlin also supports Procedural programming with use of functions. As in C and C++, the entry point to 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 supported and 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 “?” postfix after the type name. Operations on nullable objects need special care, null check must be performed before using the nullable value.
       Kotlin provides null-safe operators to help developers.
1 .  ?. (Safe navigation operator ) If the object is null method will not be called and the expression evaluates to null.
2 . ?:(null coalescing operator) often referred as Elvis operator

// Use of Elvis operator
fun wishGoodMorning(someNullableValue : String?, someNonNullableValue : Int){
val  name : String= someNullableValue ?:  “Stranger”
println(“Good morning $name”)
}
// Use of safe navigation operator
Foo  ?.   bar()  ?.    Baz()
//returns null if foois null, or bar() returns null, or baz() returns null
Tools :
1 . IntelliJ DEA has plugin support for Kotlin.
2 . JetBrains also provides a plugin for Eclipse.
3 . Integration with common Java build tools is supported including Apache Maven, Apache Ant and Gradle.             

                                                             Next : Why kotlin is good




0 comments: