Slide 1

Slide 1 text

Why I Left Java For Kotlin Sam Edwards - @HandstandSam

Slide 2

Slide 2 text

Sam Edwards

Slide 3

Slide 3 text

Outline ●The Current State of Java & Kotlin ●Live Coding - Kotlin Language Features ●What Else is Possible with Kotlin ●Conclusion

Slide 4

Slide 4 text

I Love Java ❤

Slide 5

Slide 5 text

My First… • Job out of college was writing Java • Google App Engine Backend • Android app was written in Java

Slide 6

Slide 6 text

Java 6? Who is Using "

Slide 7

Slide 7 text

Java 7? Who is Using # $

Slide 8

Slide 8 text

Java 8? Who is Using &$ '() #'

Slide 9

Slide 9 text

Java 9,10,11,12,13,14? Who is Using *

Slide 10

Slide 10 text

Java Releases https://en.wikipedia.org/wiki/Java_version_history 10

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Kotlin

Slide 13

Slide 13 text

Kotlin 13

Slide 14

Slide 14 text

Android Community Driven Adoption

Slide 15

Slide 15 text

Officially Supported Language (2017)

Slide 16

Slide 16 text

Preferred Language for Android (2019)

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Kotlin Releases • Started - 2010 • 1.0 - 2016 • 1.1 - 2017 • 1.2 - 2017 • 1.3 - 2018 • 1.4 - Almost… 2020…

Slide 21

Slide 21 text

Fast Evolution of Kotlin ●Decoupled From Java Virtual Machine (JVM) ●Compiler Plugin + Standard Libraries -> Java Bytecode

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

It’s The Little Things

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Why I Left Java for Kotlin - Live Coding https://github.com/handstandsam/why-i-left-java-for-kotlin

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Coroutines

Slide 29

Slide 29 text

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)
 }

Slide 30

Slide 30 text

“Essentially, coroutines are light-weight threads. They are launched in a context of some CoroutineScope.”

Slide 31

Slide 31 text

“Essentially, coroutines are light-weight threads. They are launched in a context of some CoroutineScope.”

Slide 32

Slide 32 text

(Developer) Happiness

Slide 33

Slide 33 text

Developer Happiness is REAL

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Kotlin Adoption

Slide 36

Slide 36 text

GitHub Repositories Created in 2020 ● Java: 1,034,837
 https://github.com/search?q=created%3A%3E2019-01-01+language%3AJava&type=Repositories&ref=advsearch&l=Java&l= ● Kotlin: 100,798 
 https://github.com/search?q=created%3A%3E2020-01-01+language%3Akotlin&type=Repositories

Slide 37

Slide 37 text

What Else is Possible with Kotlin?

Slide 38

Slide 38 text

Kotlin Multiplatform ●Android + iOS Code Sharing ●JavaScript ●Mac, Linux, Window

Slide 39

Slide 39 text

Multiplatform Libraries https://github.com/AAkira/Kotlin-Multiplatform-Libraries

Slide 40

Slide 40 text

Kotlin Native

Slide 41

Slide 41 text

Not All Roses

Slide 42

Slide 42 text

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”

Slide 43

Slide 43 text

I Love Kotlin ❤

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

Why I Left Java For Kotlin Sam Edwards - @HandstandSam Thank You!

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Kotlin to Java Bytecode

Slide 48

Slide 48 text

Kotlin Compilation to Java Bytecode Code.kt Code.class Kotlin Compiler

Slide 49

Slide 49 text

Java Decompiler (Using Fernflower) Code.class Java Decompiler Code.java

Slide 50

Slide 50 text

Magic Code.kt Code.class Kotlin Compiler Java Decompiler Code.java

Slide 51

Slide 51 text

Code.kt Code.class Kotlin Compiler Java Decompiler Code.java