SlideShare a Scribd company logo
Privet Kotlin
Hello Kotlin
Hello Kotlin
Cody Engel
Senior Software Engineer @ Yello
Free T-Shirts & Clean Code
Nick Cruz
Android Engineer @ Yello
Mr. Plantastic & Crispy Animations
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
Developed in 2011 by JetBrains
(IntelliJ IDEA, RubyMine, PhpStorm, Android Studio)
Released 2012
Statically typed programming language
for the JVM
Developed in 2011 by JetBrains
(IntelliJ IDEA, RubyMine, PhpStorm)
Released 2012
Statically typed programming language
for the JVM
Runs on JVM = 100% Interoperability with Java
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
1. Fun Facts
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
2. Getting Started
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
Functions
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
Functions
sum( , b:Int) {
return a + b
}
fun a: Int : Int
fun sum(a: Int, b: Int) = a + b
Functions
Functions
fun printSum(a: Int, b: Int): Unit {
println("sum of $a and $b is ${a + b}")
}
fun printSum(a: Int, b: Int) {
println("sum of $a and $b is ${a + b}")
}
Functions
Variables
val immutable: Int = 1
Variables
val immutable = 2
Variables
val immutable: Int
immutable = 3
Variables
var mutable = 0
mutable++
mutable++
Variables
Properties
class Address {
var name: String = ...
var street: String = ...
var city: String = ...
var state: String? = ...
var zip: String = ...
}
Properties
fun copyAddress(address: Address): Address {
val result = Address()
result.name = address.name
result.street = address.street
return result
}
Properties
val isEmpty: Boolean
get() = this.size == 0
Properties
var stringRepresentation: String
get() = this.toString()
set(value) {
field = value.toString()
}
Properties
String Templates
val = "Java"
println(
String.format("The way is terrible!", )
)
java
java%s
String Templates
String Templates
val = "Java"
println(
String.format("The way is terrible!", )
)
java
java%s
val = "Kotlin"
println("The way is awesome!")
kotlin
$kotlin
String Templates
String Templates
val = "Kotlin"
println("The way is awesome!")
kotlin
$kotlin
Control Flow
var max = a
if (a < b) max = b
Control Flow - If Expression
var max: Int
if (a > b) {
max = a
} else {
max = b
}
Control Flow - If Expression
val max = if (a > b) a else b
Control Flow - If Expression
val max = if (a > b) {
print("Returns a")
a
} else {
print("Returns b")
b
}
Control Flow - If Expression
when (x) {
1 -> print("x == 1")
2 -> print("x == 2")
else -> {
print(“x is neither 1 nor 2")
}
}
When Expression - Replaces Switch
when (x) {
1, 2 -> print("x == 1 or a == 2")
else -> print(“x is neither 1 nor 2”)
}
When Expression - Replaces Switch
when (x) {
in 1..10 -> print("x is in the range")
in validNumbers -> print("x is valid")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
}
When Expression - Replaces Switch
when {
x.isOdd() -> print("x is odd")
x.isEven() -> print("x is even")
else -> print("x is funny")
}
When Expression - Replaces If/Else If
for (item in collection) {
print(item)
}
For Loops
for (i in array.indices) {
print(array[i])
}
For Loops
for ((index, value) in array.withIndex()) {
println("the element at $index is $value")
}
For Loops
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
1. Fun Facts
2. Getting Started
4. Our Favorite Things About Kotlin
5. Kotlin At Work
3. Null Safety
Null Safety
(and Immutability)
Caused by: java.lang.NullPointerException: Attempt
to invoke virtual method 'java.lang.String
java.lang.String.trim()' on a null object
reference
Nullable String s; val s: String?
NonNull String s; val s: String
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
val length = s!!.length
NonNull Assert
val length = s!!.length
NonNull Assert
kotlin.KotlinNullPointerException
at part2.delegation.interceptor.LoggerList.add(LoggerList.kt:39)
(don’t do this)
val length = s!!.length
val length = s?.length // Int?
NonNull Assert
Safe call, returns optional
kotlin.KotlinNullPointerException
at part2.delegation.interceptor.LoggerList.add(LoggerList.kt:39)
(don’t do this)
val length = s?.length ?: 0 // Int
Safe Call and Elvis Operator
val length = s?.length ?: 0 // Int
Safe Call and Elvis Operator
Other helpful operators
with, apply, let, run
s?.let {
val length = it.length // Int
// Do stuff with length
}
What about variables that become null?
What about variables that become non-null?
Mutable
Nullable
String s; var s: String?
Mutable
NonNull
String s; var s: String
Immutable
Nullable
final String s; val s: String?
Immutable
NonNull
final String s; val s: String
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
1. Fun Facts
2. Getting Started
3. Null Safety
5. Kotlin At Work
4. Our Favorite Things About Kotlin
Classes
Data Classes
We frequently create classes whose main purpose is to
hold data. In such a class some standard functionality
and utility functions are often mechanically derivable
from the data. In Kotlin, this is called a data class.
Data Classes
data class User(val name: String, val age: Int)
data class User(
val name: String = "",
val age: Int = 0
)
Data Classes
val user = User(“Jane Smith", 27)
user.name
user.age
user.toString()
user.hashCode()
user.equals()
Data Classes
val jack = User(name = "Jack", age = 1)
val olderJack = jack.copy(age = 2)
Data Classes
val jane = User("Jane", 35)
val (name, age) = jane
println("$name, $age years of age")
Data Classes
Sealed Classes
Sealed classes are used for representing restricted
class hierarchies, when a value can have one of the
types from a limited set, but cannot have any other type.
They are, in a sense, an extension of enum classes: the
set of values for an enum type is also restricted, but
each enum constant exists only as a single instance,
whereas a subclass of a sealed class can have multiple
instances which can contain state.
sealed class Expr {
data class Const(val number: Double) : Expr()
data class Sum(val e1: Expr, val e2: Expr) : Expr()
object NotANumber : Expr()
}
Sealed Classes
Sealed Classes
fun eval(expr: Expr): Double = when(expr) {
is Const -> expr.number
is Sum -> eval(expr.e1) + eval(expr.e2)
NotANumber -> Double.NaN
}
Lambdas
& Higher-Order Functions
A higher-order function is a function
that takes functions as parameters,
or returns a function.
fun transform1Through5(transform: (Int) -> Int) {
for (int in 1..5) {
println(transform(int))
}
}
fun transform1Through5(transform: (Int) -> Int) {
for (int in 1..5) {
println(transform(int))
}
}
Method Reference
class NumberDoubler {
fun run(int: Int) = int * 2
}
fun doubleNumbersMethodReference() {
val numberDoubler = NumberDoubler()
transform1Through5(numberDoubler::run)
}
Lambda
fun transform1Through5(transform: (Int) -> Int) {
for (int in 1..5) {
println(transform(int))
}
}
fun doubleNumbersLambda() {
transform1Through5 { num -> num * 2 }
}
transform1Through5 { num -> num * 2 }
transform1Through5 { it * 2 }
transform1Through5 { it * 3 }
transform1Through5 { it * 30 }
transform1Through5 { it * it }
listOf(1, 2, 3, 4, 5)
.filter { it % 2 == 1 } // Filter evens: [1, 3, 5]
.map { it * 2 } // Double the results: [2, 6, 10]
.forEach { println(it) } // Print them
Kotlin Collections
listOf(1, 2, 3, 4, 5)
.filter { it % 2 == 1 } // Filter evens: [1, 3, 5]
.map { it * 2 } // Double the results: [2, 6, 10]
.forEach { println(it) } // Print them
Kotlin Collections
Observable.just(1, 2, 3, 4, 5)
.filter { it % 2 == 1 }
.map { it * 2 }
.forEach { println(it) }
RxJava Observable (in Kotlin)
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
1. Fun Facts
1. Fun Facts
2. Getting Started
3. Null Safety
4. Our Favorite Things About Kotlin
5. Kotlin At Work
@
Introduce Kotlin
@
Introduce Kotlin
• Discuss the benefits of Kotlin.
• Give snippets in Pull Request comments.
• Get others on our team interested.
@
Learn Together
@
Learn Together
• Work through Kotlin Koans together.
• Watch Kotlin videos together.
• Make this a team effort.
@
Kotlin In Production
@
Kotlin In Production
• Determine code style rules as a team.
• Find the path of least resistance.
• Java-style Kotlin in the beginning.
• Focus on continuous improvement.
@
twitter.com/POTUS404
medium.com/@CodyEngel
github.com/CodyEngel github.com/NickCruz
medium.com/@NickCruz26
twitter.com/ReactiveNick
medium.com/yello-offline
instagram.com/yello_offline
twitter.com/yello_offline
Resources
Kotlin Koans
https://goo.gl/MTLEYg
KotlinLang
https://kotlinlang.org
Life is Great and Everything Will Be Ok, Kotlin Is Here
https://goo.gl/yhp2Gn
Kotlin Uncovered
https://goo.gl/fbAFW5
Introduction To Kotlin
https://goo.gl/iCwYHd

More Related Content

PDF
Sneaking inside Kotlin features
PDF
Feel of Kotlin (Berlin JUG 16 Apr 2015)
PDF
Idiomatic Kotlin
ODP
Scala introduction
PPTX
Introduction to kotlin + spring boot demo
PPT
Scala presentation by Aleksandar Prokopec
PDF
Comparing JVM languages
PDF
Kotlin, why?
Sneaking inside Kotlin features
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Idiomatic Kotlin
Scala introduction
Introduction to kotlin + spring boot demo
Scala presentation by Aleksandar Prokopec
Comparing JVM languages
Kotlin, why?

What's hot (20)

PDF
Kotlin Bytecode Generation and Runtime Performance
KEY
Into Clojure
PPTX
Kotlin – the future of android
PDF
Advanced Debugging Using Java Bytecodes
PDF
3 kotlin vs. java- what kotlin has that java does not
PDF
Lezione03
PDF
2 kotlin vs. java: what java has that kotlin does not
PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
PDF
Kotlin advanced - language reference for android developers
PDF
Kotlin: a better Java
ODP
AST Transformations
PPTX
Kotlin collections
PDF
Haskell in the Real World
ODP
Ast transformations
PDF
Why Haskell
PDF
Clojure for Java developers - Stockholm
PDF
core.logic introduction
PDF
Orthogonal Functional Architecture
PPTX
Introduction to Kotlin
Kotlin Bytecode Generation and Runtime Performance
Into Clojure
Kotlin – the future of android
Advanced Debugging Using Java Bytecodes
3 kotlin vs. java- what kotlin has that java does not
Lezione03
2 kotlin vs. java: what java has that kotlin does not
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Kotlin advanced - language reference for android developers
Kotlin: a better Java
AST Transformations
Kotlin collections
Haskell in the Real World
Ast transformations
Why Haskell
Clojure for Java developers - Stockholm
core.logic introduction
Orthogonal Functional Architecture
Introduction to Kotlin
Ad

Similar to Privet Kotlin (Windy City DevFest) (20)

PDF
Kotlin for Android Developers - 3
PDF
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
PDF
Kotlin 1.2: Sharing code between platforms
PDF
Kotlin, smarter development for the jvm
PDF
Introduction kot iin
PPTX
Scala for curious
PDF
Game Design and Development Workshop Day 1
PPTX
K is for Kotlin
ODP
Introduction to Scala
PDF
Intro to Kotlin
PDF
Introduction to Scala
PDF
Kotlin for Android devs
PDF
Scala coated JVM
PDF
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
ODP
PDF
Kotlin @ Coupang Backend 2017
PDF
Lezione03
PPTX
Android & Kotlin - The code awakens #03
PDF
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Kotlin for Android Developers - 3
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Kotlin 1.2: Sharing code between platforms
Kotlin, smarter development for the jvm
Introduction kot iin
Scala for curious
Game Design and Development Workshop Day 1
K is for Kotlin
Introduction to Scala
Intro to Kotlin
Introduction to Scala
Kotlin for Android devs
Scala coated JVM
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Kotlin @ Coupang Backend 2017
Lezione03
Android & Kotlin - The code awakens #03
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Ad

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Understanding Forklifts - TECH EHS Solution
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
AI in Product Development-omnex systems
PDF
Digital Strategies for Manufacturing Companies
PPTX
ai tools demonstartion for schools and inter college
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administraation Chapter 3
PDF
PTS Company Brochure 2025 (1).pdf.......
Upgrade and Innovation Strategies for SAP ERP Customers
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Understanding Forklifts - TECH EHS Solution
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How Creative Agencies Leverage Project Management Software.pdf
AI in Product Development-omnex systems
Digital Strategies for Manufacturing Companies
ai tools demonstartion for schools and inter college
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Odoo Companies in India – Driving Business Transformation.pdf
ISO 45001 Occupational Health and Safety Management System
Navsoft: AI-Powered Business Solutions & Custom Software Development
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
CHAPTER 2 - PM Management and IT Context
System and Network Administraation Chapter 3
PTS Company Brochure 2025 (1).pdf.......

Privet Kotlin (Windy City DevFest)