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

Modern Android Development with Kotlin

Adora Nwodo
December 05, 2018

Modern Android Development with Kotlin

This presentation talks about Kotlin: the new language for building native Android Applications

Adora Nwodo

December 05, 2018
Tweet

More Decks by Adora Nwodo

Other Decks in Programming

Transcript

  1. Hi, I’m Adora Full Stack Web Developer Google Associate Android

    Developer Writer, adorahack.com Twitter: @theadoranwodo, @adorahack GitHub: @adoranwodo 2
  2. ▣ Runs on the JVM ▣ Statically typed language ▣

    Gets rid of Java NullPointerException ▣ Interoperable ▣ Safer code ▣ Gets rid of boilerplate code ▣ Modern programming language ▣ Easier way to develop Android apps 4 Why Kotlin?
  3. JAVA public class Person{ private String firstname, lastname; public Person(String

    fname, String lname){ this.firstname = fname; this.lastname = lname; } public String getFirstname(){ return firstname; } public String getLastname(){ return lastname; } Public void setFirstname(string firstname){ this.firstname = firstname; } Public void setLastname(string firstname){ this.lastname = lastname; } } KOTLIN data class Person(var firstname: String, var lastname: String) 6 Code less. Do more.
  4. 7

  5. Syntax Let’s write some code 1. Basic Types 2. Switch

    2.0 - When 3. Data Class 4. Sealed Class 5. Lambda Expressions 8
  6. 9 Basic Types var a: Int = 100 var b:

    Float = 100.00f var c: Char = ‘a’ var isDeveloper: Boolean = true var name: String = “Adora” val numbers: IntArray = intArrayOf(1,2,3,4,5,6,7,8,9,0) val numbers: MutableList<Int> = mutableListOf(1, 2, 3) val readOnlyNumbers: List<Int> = numbers
  7. Simple form when (x) { 1 -> print("x == 1")

    2 -> print("x == 2") else -> { print("x is neither 1 nor 2") } } 10 Switch 2.0 - When Multiple cases when (x) { 0, 1 -> print("x == 0 or x == 1") else -> print("otherwise") } Range when (x) { in 1..10 -> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") }
  8. 11 Data Class data class Person(var firstname: String, var lastname:

    String) val person = Person(“Nenne”, “Nwodo”) //no new keyword print(person.firstname) // prints Nenne print(person.lastname) // prints Nwodo
  9. 12 Sealed Class Sealed classes are used when a value

    can have only one of the types from a limited set (restricted hierarchies). Sealed classes cannot have public constructors sealed class Animal{} class Monkey: Animal() class Dog: Animal() Fun animalType (a: Animal) = when(a){ Is Monkey -> print(“Monkey”) Is Dog -> print(“Dog”) }
  10. 13 Lambda Expressions Higher order functions take functions as a

    parameter and returns a function. Lambda reduces boilerplate code Fun sampleFunction(x: String, doStuff: (String)->String){ //higher order function doStuff(x) } //lambda expression val doStuff: (String) -> String = { s -> “Hello $s” } sampleFunction(“Adora”, doStuff)
  11. Tools Want to make things easier than they already are?

    1. Anko 2. Kotlin Android Extensions 3. RxKotlin 4. Spek 5. Kotson 14
  12. Anko Super hero Kotlin Library for Android Anko consists of

    a lot of extension functions to make Android development easier 15
  13. 16

  14. RxKotlin Kotlin extensions for RXJava RxKotlin is a lightweight library

    that adds convenient extension functions to RxJava. 18
  15. 19

  16. Spek Write Tests Rewrite of Spek with Kotlin Multi Platform

    framework in mind. Reworked in Specification & Gherkin. 20
  17. 21

  18. Kotson Gson for Kotlin Parse and write JSON with Google’s

    Gson using a conciser and easier syntax 22
  19. 23

  20. How do I get started? ▣ Udacity ▣ Udemy ▣

    Lynda ▣ https://kotlinlang.org/ ▣ https://developer.android.com/kotlin/ ▣ https://github.com/JetBrains/kotlin 28
  21. Thanks! 33 Website - www.adoranwodo.com Blog - www.adorahack.com GitHub -

    @adoranwodo Twitter - @theadoranwodo, @adorahack