Lecture-11-Kotlin.pdf - EE382V ADVANCED PROGRAMMING TOOLS FALL 2019 KOTLIN KOTLIN Resources Kotlin Workshop https\/github.com\/jetbrains\/kotlin-workshop

Lecture-11-Kotlin.pdf - EE382V ADVANCED PROGRAMMING TOOLS...

This preview shows page 1 - 18 out of 106 pages.

KOTLIN EE382V ADVANCED PROGRAMMING TOOLS FALL 2019
Image of page 1
KOTLIN Resources: Kotlin Workshop Kotlin in Action by Dmitry Jemerov and Svetlana Isakova (book)
Image of page 2
Christine Julien, Fall 2019 KOTLIN INTRODUCTION WHAT IS KOTLIN? Programming language from JetBrains (developers of IntelliJ) Concise, Safe, Interoperable In particular 100% interoperable with Java A language of choice for Android Functional and object oriented Free and open source
Image of page 3
Christine Julien, Fall 2019 KOTLIN INTRODUCTION 4 Sketchnote by Chui-Ki Chan ()
Image of page 4
Christine Julien, Fall 2019 KOTLIN INTRODUCTION KOTLIN BUILD PROCESS 5 definitions of Kotlin’s standard library classes and extensions to the JVM
Image of page 5
Christine Julien, Fall 2019 KOTLIN INTRODUCTION THE KOTLIN PHILOSOPHY Pragmatic Concise Safe Interoperable
Image of page 6
Christine Julien, Fall 2019 KOTLIN INTRODUCTION KOTLIN PRAGMATISM Not a research language Builds on tried and true programming language practice Incorporates things that work from other languages Does not enforce programmings style or paradigms
Image of page 7
Christine Julien, Fall 2019 KOTLIN INTRODUCTION WHAT IS CONCISE IN KOTLIN? data class Person( val firstname: String, var lastname: String, var age: Int) public class Person{ final String firstname; String last name; int age; public Person(...) { ... } // Getters ... // Hashcode / equals ... // toString ... // Etc. POJO “Plain old Java Object” with all that other stuff “for free”
Image of page 8
Christine Julien, Fall 2019 KOTLIN INTRODUCTION WHAT IS SAFE ABOUT KOTLIN? It’s statically typed (i.e., types are checked at compile time) (Like Java, C++, etc., but unlike Python) But the big win (IMO) is the built-in “null safety” Explicitly distinguish between variables that can be null and those that cannot More later
Image of page 9
Christine Julien, Fall 2019 KOTLIN INTRODUCTION … AND INTEROPERABILITY? Kotlin is compiled into Java byte code and interpreted by the JVM Kotlin and Java can play together in the same project Also IntelliJ/Android Studio has a very functional Java to Kotlin converter Kotlin is from an IDE company, so the tool support is direct and excellent Kotlin Koans is a nice online playground
Image of page 10
Christine Julien, Fall 2019 try.kotl.in
Image of page 11
KOTLIN BASICS (QUICKLY)
Image of page 12
Christine Julien, Fall 2019 KOTLIN BASICS KOTLIN VARIABLES val (read only) and var (mutable) val firstname: String = "Christine" firstname = "Bob" // not allowed (immutable) var lastname: String = "West" lastname = "Julien" lastname = 42 // not allowed (type mismatch)
Image of page 13
Christine Julien, Fall 2019 KOTLIN BASICS OBJECT INSTANTIATION i.e., creating objects based on a defined class type val sb: StringBuilder = StringBuilder("Here") // no explicit "new" call to the constructor sb.append(" is some").append(" text!") println(sb)
Image of page 14
Christine Julien, Fall 2019 KOTLIN BASICS FUNCTIONS : CLASSIC fun maximum(first: Int, second: Int): Int { if (first > second) { return first } else { return second } }
Image of page 15
Christine Julien, Fall 2019 KOTLIN BASICS FUNCTIONS : “IF” AS AN EXPRESSION fun maximum(first: Int, second: Int): Int { return if (first > second) { first } else { second } }
Image of page 16
Christine Julien, Fall 2019 KOTLIN BASICS FUNCTIONS : DEFAULT PARAMETERS fun maximum(first: Int = 3, second: Int = 4): Int { return if (first > second) { first } else { second } }
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 106 pages?

  • Fall '08
  • Staff

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture