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

JAVA vs KOTLIN

JAVA vs KOTLIN

The key difference between Java and Kotlin is given with details. Java is great and highly accepted across platforms, but its getting old.
Why is Kotlin taking so much preference and why should one prefer Kotlin? All the details are explained here.

Deesha Vora

March 08, 2018
Tweet

More Decks by Deesha Vora

Other Decks in Programming

Transcript

  1. JAVA vs KOTLIN Which one to choose and Why? By

    Deesha Vora (@Deesharv, [email protected]) Co-founder and CPO @SuperWiseSite
  2. 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
  3. 5

  4. Function types in Kotlin. Function accepting another function. fun <T>

    max(collection: Collection<T>, less: (T, T) -> Boolean): T? { var max: T? = null for (it in collection) if (max == null || less(max, it)) max = it return max } 6
  5. Functional collection extensions JoinToString (fun <T> Iterable<T>.joinToString()) Creates a string

    from all the elements separated using separator and using the given prefixand postfix if supplied. Any (fun <T> Array<out T>.any(): Boolean) Returns true if array has at least one element. Associate (fun <T, K, V> Iterable<T>.associate( transform: (T) -> Pair<K, V>): Map<K, V>) Returns a Map containing key-value pairs provided by transform function applied to elements of the given collection. 7
  6. lateinit, Delegates.notNull and lazy val movie: String var name: String?

    = null lateinit var name: String var age: Int by Delegates.notNull<Int>() val imm: InputMethodManager by lazy { getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager } 8
  7. 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
  8. 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 }
  9. 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
  10. 13

  11. 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.