Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Kotlin

Avatar for Livin Livin
October 21, 2017

Intro to Kotlin

At the latest Google I/O conference, Google announced that Android development would now fully support Kotlin. This is big news as it opens up an entirely new avenue for those that want to start creating their own Android applications. And seeing as Kotlin is highly popular and has a lot of unique features, it creates new opportunities for existing developers too.

Kotlin is a statically typed programming language from JetBrains. It is fully ‘inter-operable’ with Java (meaning you can use Java frameworks and even mix commands from both in your code) and comes with no limitations. Android developers have actually been using Kotlin for some time already via a plugin and some popular apps on the Play Store (like Basecamp) were reportedly built solely using Kotlin. Now though, as of the forthcoming Android Studio 3.0, it will be bundled-in and supported out-of-the-box.

Avatar for Livin

Livin

October 21, 2017

Other Decks in Programming

Transcript

  1. Some Java issues addressed in Kotlin - Null references are

    addressed by type system - No raw type - Invariant Arrays - Proper function types - Use-site variance - No checked exceptions
  2. What Java has that Kotlin does not? - Checked Exceptions

    - Primitive Types - Static Members - Non-private fields - Wildcard-types - NullPointerException
  3. Mutable and Immutable objects val pi = 3.14 var rad

    = 5 var hello: String = “Hello World” val key: String = “GDG Cochin”
  4. Null Safety var a = null var hello: String =

    null var hello: String? = null var hello: String lateinit var hello: String
  5. Ranges val a = 1..4 val a = 4..1 val

    a = 4 downto 1 val a = 1 until 4 val a = 1..10 step 2
  6. Strings Templates val i = 8 val s = “i

    = $i” val str = abc print(“Length of $str is ${str.length}”) Length of abc is 3 i = 8
  7. Conditional Constructs if(a > b){ s = “larger” } else

    { s = “smaller” } val s = if(a > b) “Larger” else “Smaller”
  8. val s = if(a > b){ print(“a is largest”) “Larger”

    } else { print(“b is largest”) “Smaller” }
  9. Looping Constructs for( object in objects ) print(object.name) while( a

    > b ){ a = a + c } do{ val y = doSomething() }while( y != null )
  10. Class - Final class - Open class - Object class

    - Data class class Dog{ var breed; }
  11. Constructors - Primary class Dog(var breed:String, var age:Int) - Secondary

    class Dog{ constructor(var breed:String, var age:Int){} }
  12. Lambda - Function Literal - Function that is not declared

    but passed immediately as an expression