SlideShare a Scribd company logo
Just Kotlin
What is Kotlin?
A language from JetBrains
100% Interop with Java
Compile to JVM, Android, and JavaScript
Why is Kotlin interesting
A pragmatic approach, basically a better Java -> easier to migrate
It compiles to (among others) Java 6 bytecode -> sweet spot: Android
First class IDE support with conversion tool
Concise Syntax: Type Inference
val a: Int = 1
val b = 1 // `Int` type is inferred
val c: Int // Type required when no initializer is provided
var x = 5 // Mutable, `Int` type is inferred
Concise Syntax: Data Class
public class Person {
final String firstName;
final String lastName;
public Person(...) {
...
}
// Getters
...
// Hashcode / equals
...
// Tostring
...
// Egh...
}
data class Person(
val firstName: String,
val lastName: String
)
Extension Functions
fun MutableList<Int>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to the list
this[index1] = this[index2]
this[index2] = tmp
}
val l = mutableListOf(1, 2, 3)
l.swap(0, 2) // 'this' inside 'swap()' will hold the value of 'l'
Handling null values
var a: String = "abc"
a = null // compilation error
var a: String? = "abc"
a = null // ok
if (a != null) {
print("String of length ${a.length}") //a can’t be null in this scope
}
//val bob: Employee?
bob?.department?.head?.name?:"John Doe"
FP: Lambda
strings.filter { it.length == 5 }
.sortBy { it }
.map { it.toUpperCase() }
FP: Algebraic Data Types
sealed class Maybe<out T> {
object None : Maybe<Nothing>()
class Just<T>(val t: T) : Maybe<T>()
}
//Pattern matching
class User(val age: Int)
fun lookupFromDB(s: String): Maybe<User> = //........
fun printUser(username: String) {
val rec = lookupFromDB(username)
when (rec) {
is Maybe.None -> println("not found")
is Maybe.Just<User> -> println("${rec.t.age} years old")
}
}
FP: Immutability
//class
data class Person(val name: String, val age: Int)
val mike = Person("Mike", 31)
val olderMike = mike.copy(age = 32)
//collection
val people = listOf(mike, olderMike)
people.add(Person("Bob", 50)) // ERROR
val peopleDB = arrayListOf(mike, olderMike)
peopleDB.add(Person("Bob", 50))
FP: Currying and Partial
//curry
val sum2ints = { x: Int, y: Int -> x + y }
val curried: (Int) -> (Int) -> Int = sum2ints.curried()
assertEquals(curried(2)(4), 6)
val add5 = curried(5)
assertEquals(add5(7), 12)
//partial
val format = { prefix: String, x: String, postfix: String -> "${prefix}${x}${postfix}" }
val prefixAndBang = format(p3 = "!")
// Passing just the first parameter will return a new function
val hello = prefixAndBang(p1 = "Hello, ")
println(hello("world"))

More Related Content

What's hot (20)

PDF
Chapter23 friend-function-friend-class
Deepak Singh
 
PPT
JavaScript Data Types
Charles Russell
 
PPT
Project Lambda - Closures after all?
Andreas Enbohm
 
PDF
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
PPT
Basic Javascript
Bunlong Van
 
ODP
Hands on Session on Python
Sumit Raj
 
PPT
The Kotlin Programming Language
intelliyole
 
PDF
What are monads?
José Luis García Hernández
 
PPT
Lecture5
Sunil Gupta
 
PPTX
‫Object Oriented Programming_Lecture 3
Mahmoud Alfarra
 
PDF
History of C#
aschlapsi
 
PPTX
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
PDF
Scala Types of Types @ Lambda Days
Konrad Malawski
 
PDF
Biopython: Overview, State of the Art and Outlook
Asociación Argentina de Bioinformática y Biología Computacional
 
PPTX
Adventures in TclOO
Donal Fellows
 
PDF
Introduction To Scala
Peter Maas
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Crystal presentation in NY
Crystal Language
 
PPTX
TclOO: Past Present Future
Donal Fellows
 
PDF
Crystal internals (part 1)
Ary Borenszweig
 
Chapter23 friend-function-friend-class
Deepak Singh
 
JavaScript Data Types
Charles Russell
 
Project Lambda - Closures after all?
Andreas Enbohm
 
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Basic Javascript
Bunlong Van
 
Hands on Session on Python
Sumit Raj
 
The Kotlin Programming Language
intelliyole
 
Lecture5
Sunil Gupta
 
‫Object Oriented Programming_Lecture 3
Mahmoud Alfarra
 
History of C#
aschlapsi
 
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
Scala Types of Types @ Lambda Days
Konrad Malawski
 
Biopython: Overview, State of the Art and Outlook
Asociación Argentina de Bioinformática y Biología Computacional
 
Adventures in TclOO
Donal Fellows
 
Introduction To Scala
Peter Maas
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Crystal presentation in NY
Crystal Language
 
TclOO: Past Present Future
Donal Fellows
 
Crystal internals (part 1)
Ary Borenszweig
 

Similar to Just Kotlin (20)

PDF
Introduction to Kotlin
Patrick Yin
 
PDF
Pure Kotlin Devoxx PL 2021
Jarek Ratajski
 
PDF
Kotlin
Nodirbek Usmanov
 
PPTX
Kotlin
YeldosTanikin
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PDF
No excuses, switch to kotlin
Thijs Suijten
 
PPTX
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
PDF
Pure kotlin
Jarek Ratajski
 
PDF
Kotlin for Android devs
Adit Lal
 
PDF
Privet Kotlin (Windy City DevFest)
Cody Engel
 
PDF
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
PDF
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Codemotion
 
PPTX
Kotlin : Happy Development
Md Sazzad Islam
 
PDF
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
PDF
2014-11-01 01 Денис Нелюбин. О сортах кофе
Омские ИТ-субботники
 
PDF
Kotlin for Android Developers
Hassan Abid
 
PDF
Kotlin: a better Java
Nils Breunese
 
PPTX
Android Application Development (1).pptx
adityakale2110
 
PDF
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
PDF
Kotlin- Basic to Advance
Coder Tech
 
Introduction to Kotlin
Patrick Yin
 
Pure Kotlin Devoxx PL 2021
Jarek Ratajski
 
A quick and fast intro to Kotlin
XPeppers
 
No excuses, switch to kotlin
Thijs Suijten
 
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
Pure kotlin
Jarek Ratajski
 
Kotlin for Android devs
Adit Lal
 
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Codemotion
 
Kotlin : Happy Development
Md Sazzad Islam
 
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
2014-11-01 01 Денис Нелюбин. О сортах кофе
Омские ИТ-субботники
 
Kotlin for Android Developers
Hassan Abid
 
Kotlin: a better Java
Nils Breunese
 
Android Application Development (1).pptx
adityakale2110
 
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
Kotlin- Basic to Advance
Coder Tech
 
Ad

Recently uploaded (20)

PPT
Brief History of Python by Learning Python in three hours
adanechb21
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
 
PDF
What companies do with Pharo (ESUG 2025)
ESUG
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
 
PDF
Troubleshooting Virtual Threads in Java!
Tier1 app
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
PDF
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PPTX
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
PDF
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PPTX
Online Contractor Induction and Safety Induction Training Software
SHEQ Network Limited
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
PPTX
Processing with Claim Management Automation Solutions
Insurance Tech Services
 
Brief History of Python by Learning Python in three hours
adanechb21
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
 
What companies do with Pharo (ESUG 2025)
ESUG
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
 
Troubleshooting Virtual Threads in Java!
Tier1 app
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Online Contractor Induction and Safety Induction Training Software
SHEQ Network Limited
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
Processing with Claim Management Automation Solutions
Insurance Tech Services
 
Ad

Just Kotlin

  • 2. What is Kotlin? A language from JetBrains 100% Interop with Java Compile to JVM, Android, and JavaScript
  • 3. Why is Kotlin interesting A pragmatic approach, basically a better Java -> easier to migrate It compiles to (among others) Java 6 bytecode -> sweet spot: Android First class IDE support with conversion tool
  • 4. Concise Syntax: Type Inference val a: Int = 1 val b = 1 // `Int` type is inferred val c: Int // Type required when no initializer is provided var x = 5 // Mutable, `Int` type is inferred
  • 5. Concise Syntax: Data Class public class Person { final String firstName; final String lastName; public Person(...) { ... } // Getters ... // Hashcode / equals ... // Tostring ... // Egh... } data class Person( val firstName: String, val lastName: String )
  • 6. Extension Functions fun MutableList<Int>.swap(index1: Int, index2: Int) { val tmp = this[index1] // 'this' corresponds to the list this[index1] = this[index2] this[index2] = tmp } val l = mutableListOf(1, 2, 3) l.swap(0, 2) // 'this' inside 'swap()' will hold the value of 'l'
  • 7. Handling null values var a: String = "abc" a = null // compilation error var a: String? = "abc" a = null // ok if (a != null) { print("String of length ${a.length}") //a can’t be null in this scope } //val bob: Employee? bob?.department?.head?.name?:"John Doe"
  • 8. FP: Lambda strings.filter { it.length == 5 } .sortBy { it } .map { it.toUpperCase() }
  • 9. FP: Algebraic Data Types sealed class Maybe<out T> { object None : Maybe<Nothing>() class Just<T>(val t: T) : Maybe<T>() } //Pattern matching class User(val age: Int) fun lookupFromDB(s: String): Maybe<User> = //........ fun printUser(username: String) { val rec = lookupFromDB(username) when (rec) { is Maybe.None -> println("not found") is Maybe.Just<User> -> println("${rec.t.age} years old") } }
  • 10. FP: Immutability //class data class Person(val name: String, val age: Int) val mike = Person("Mike", 31) val olderMike = mike.copy(age = 32) //collection val people = listOf(mike, olderMike) people.add(Person("Bob", 50)) // ERROR val peopleDB = arrayListOf(mike, olderMike) peopleDB.add(Person("Bob", 50))
  • 11. FP: Currying and Partial //curry val sum2ints = { x: Int, y: Int -> x + y } val curried: (Int) -> (Int) -> Int = sum2ints.curried() assertEquals(curried(2)(4), 6) val add5 = curried(5) assertEquals(add5(7), 12) //partial val format = { prefix: String, x: String, postfix: String -> "${prefix}${x}${postfix}" } val prefixAndBang = format(p3 = "!") // Passing just the first parameter will return a new function val hello = prefixAndBang(p1 = "Hello, ") println(hello("world"))

Editor's Notes

  • #5: Look, no semicolon!
  • #8: The billion dollar mistake The smart null check also apply to instance check
  • #9: Performance optimization: inline functions With closure
  • #10: Can’t do this with data class yet though :(
  • #12: Not supported out of the box