Slide 1

Slide 1 text

JAVA vs KOTLIN Which one to choose and Why? By Deesha Vora (@Deesharv, [email protected]) Co-founder and CPO @SuperWiseSite

Slide 2

Slide 2 text

I JAVA Because... Easy Object oriented Platform-independent Portable Distributed Robust 2

Slide 3

Slide 3 text

Because I know JAVA... 3 I JAVA Really

Slide 4

Slide 4 text

Why new language “Kotlin” ? - Concise yet expressive - Function Types - Kotlin doesn’t have checked exception - Collection filtering like Swift and Java 8 - Lazy Loading feature - Data class - lateinit, Delegates.notNull - Extension functions 4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

Function types in Kotlin. Function accepting another function. fun max(collection: Collection, less: (T, T) -> Boolean): T? { var max: T? = null for (it in collection) if (max == null || less(max, it)) max = it return max } 6

Slide 7

Slide 7 text

Functional collection extensions JoinToString (fun Iterable.joinToString()) Creates a string from all the elements separated using separator and using the given prefixand postfix if supplied. Any (fun Array.any(): Boolean) Returns true if array has at least one element. Associate (fun Iterable.associate( transform: (T) -> Pair): Map) Returns a Map containing key-value pairs provided by transform function applied to elements of the given collection. 7

Slide 8

Slide 8 text

lateinit, Delegates.notNull and lazy val movie: String var name: String? = null lateinit var name: String var age: Int by Delegates.notNull() val imm: InputMethodManager by lazy { getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager } 8

Slide 9

Slide 9 text

Extension functions fun Activity.hideKeyboard(): Boolean { val view = currentFocus view ? .let { val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager return inputMethodManager.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) } return false } 9

Slide 10

Slide 10 text

JAVA CODE vs KOTLIN CODE public class User { private String firstName; private String lastName; public String getFirstName() {return firstName;} public void setFirstName(String firstName) {this.firstName = firstName;} public String getLastName() {return lastName;} public void setLastName(String lastName) {this.lastName = lastName;} } 10 class User { var firstName: String? = null var lastName: String? = null }

Slide 11

Slide 11 text

40 % cut in the number of lines of code. 11

Slide 12

Slide 12 text

The Future, Kotlin/Native - Access to Objective C APIs - Kotline can be used for both iOS and Android - From server back-end to the web or mobile clients - LLVM compiler to generate machine code - (Supports Mac OSx 10+, Ubuntu 14+, iOS arm64, Raspberry Pi ) 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

https://goo.gl/2EFxmJ 14

Slide 15

Slide 15 text

Should I learn Kotlin from today ? How? If not now, Sooner or later you will have to. It is simple if you know JAVA already. 15 Should I switch my apps to Kotlin? That depends, how old and huge is your app. 6 months to 3 months? consider changing it to kotlin 1 year or older? then wait...You might want to consider interoperability of Kotlin. Or you might not want to do it at all.

Slide 16

Slide 16 text

Still confused…? 16 Shoot your queries... Catch me @Deesharv, Email:[email protected]