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

Why I Left Java for Kotlin

Why I Left Java for Kotlin

Sam Edwards

July 21, 2020
Tweet

More Decks by Sam Edwards

Other Decks in Programming

Transcript

  1. Outline •The Current State of Java & Kotlin •Live Coding

    - Kotlin Language Features •What Else is Possible with Kotlin •Conclusion
  2. My First… • Job out of college was writing Java

    • Google App Engine Backend • Android app was written in Java
  3. Java Releases 11 J2SE 1.4 February 2002 J2SE 5.0 September

    2004 Java SE 6 December 2006 Java SE 7 July 2011 Java SE 8 (LTS) March 2014 Java SE 9 September 2017 Java SE 10 March 2018 Java SE 11 (LTS) September 2018 Java SE 12 March 2019 Java SE 13 September 2019 https://en.wikipedia.org/wiki/Java_version_history
  4. 17

  5. Kotlin Releases • Started - 2010 • 1.0 - 2016

    • 1.1 - 2017 • 1.2 - 2017 • 1.3 - 2018 • 1.4 - Almost… 2020…
  6. Fast Evolution of Kotlin •Decoupled From Java Virtual Machine (JVM)

    •Compiler Plugin + Standard Libraries -> Java Bytecode
  7. 23

  8. My Favorite Features •Java Interop •Extension Functions •Ability to Convert

    Java -> Kotlin •Null Safety •Data Classes •Immutability (val) •Named Parameters •No “new” or “;” •Higher Order Functions & Lambdas •Sealed Classes •Coroutines - Reactive Programming
  9. Kotlin Coroutines Explained in one slide • A function with

    a suspend keyword signifies it must run in a Coroutine
 
 suspend fun doNetworkRequest() : Result {
 // Network Request Occurs
 } • suspend functions must be executed within a CoroutineContext and Once inside a coroutine, code executes sequentially
 
 CoroutineContext(Dispatchers.Default).launch{
 val result = doNetworkRequest()
 processResult(result)
 }
  10. Developer Happiness •Less Boilerplate •Concise & Readable Code •Handle Nullable

    Values Proactively •Don’t have to throw away Java code •Enables Functional Programming •Enables Reactive Programming
  11. Not All Roses •Non-Ideal Interop For Some Java Frameworks and

    Libraries •Pick the right tool for the job •Not everyone knows Kotlin yet •Your team may not want to do Kotlin because it’s too “risky”
  12. Dear Java, You taught me about NullPointerExceptions, verbose code and

    mutable data. I will always love you, but I’ve met a language named Kotlin, and I’m moving on. Love, -Sam