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

Kotlin vs Java • Bapusaheb Patil • TechieAid Talk

Kotlin vs Java • Bapusaheb Patil • TechieAid Talk

Slides to a talk I gave on-stage at TechieAid about Kotlin vs Java.
Date: August 1st, 2018
My website: https://bapspatil.com

Bapusaheb Patil

August 01, 2018
Tweet

More Decks by Bapusaheb Patil

Other Decks in Programming

Transcript

  1. Kotlin vs Java Bapusaheb Patil Google Certified Android Developer &

    OpenClassrooms Android Mentor www.bapspatil.com TechieAid
  2. www.bapspatil.com • Requires more code to do simple tasks. •

    NullPointerExceptions make life hell. • Not that friendly with Android.
  3. www.bapspatil.com Enter, Kotlin. • Takes care of null-safety. • More

    concise & much shorter code. • Runs on JVM. • Can be used along with Java files. ...and more that can’t be covered in my talk.
  4. www.bapspatil.com Basic Data Types • Double • Float • Long

    • Int • Short • Byte • Boolean • Char • String • Array
  5. www.bapspatil.com Declaring A Variable... • var - Mutable variable •

    val - Immutable or final variable Example: var name: String? = “TechieAid” val students: Int = 120 ? means the variable can be null.
  6. www.bapspatil.com Null-Safety // Doesn’t compile, to be safe. var name:

    String = null // Compiles safely var name: String? = null
  7. www.bapspatil.com Java Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() {

    @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), “Hey there!”, Toast.LENGTH_SHORT).show(); } } Kotlin button.onClick { toast(“Hey there!”) }
  8. www.bapspatil.com Java public class User { private int id; private

    String name; public User() { } public User(String name, int id) { this.id = id; this.name = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String toString() { return “User: “ + “ID=” + this.id + “Name=” + this.name; } } Kotlin data class User ( val id: Int, val name: String ) And that’s another reason Kotlin rules!
  9. www.bapspatil.com Great! Where Do I Learn Kotlin From? Kotlinlang.org •

    Official Website & Documentation Google Codelabs • Kotlin Is Awesome! • kotlin.link Mindorks.com • Talking Kotlin • Kotlin Bootcamp for Programmers •