KOTLIN
EE382V ADVANCED PROGRAMMING TOOLS
FALL 2019

KOTLIN
Resources:
Kotlin Workshop
Kotlin in Action by Dmitry Jemerov and Svetlana Isakova
(book)

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

Christine Julien, Fall 2019
KOTLIN INTRODUCTION
4
Sketchnote by Chui-Ki Chan ()

Christine Julien, Fall 2019
KOTLIN INTRODUCTION
KOTLIN BUILD PROCESS
5
definitions of Kotlin’s
standard library classes
and extensions to the JVM

Christine Julien, Fall 2019
KOTLIN INTRODUCTION
THE KOTLIN PHILOSOPHY
▸
Pragmatic
▸
Concise
▸
Safe
▸
Interoperable

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

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”

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

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

Christine Julien, Fall 2019
try.kotl.in

KOTLIN BASICS
(QUICKLY)

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)

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)

Christine Julien, Fall 2019
KOTLIN BASICS
FUNCTIONS : CLASSIC
fun maximum(first: Int, second: Int): Int {
if (first > second) {
return first
} else {
return second
}
}

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

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


You've reached the end of your free preview.
Want to read all 106 pages?
- Fall '08
- Staff