SlideShare a Scribd company logo
Let’s fly to the Kotlin
island
short and comprehensive introduction
Aliaksei Zhynhiarouski
1
http://try.kotl.in
2
Kotlin Island
3
Why is Kotlin
• Static Typing
• Java + Kotlin = ❤. 

Effortless mixing both in one project
• Java Interoperability. 

100% interoperable with Java.
4
Why is Kotlin
• Null Safety
• Type Inference
• Immutability in the mind
• fun
5
fun main(args : Array<String>) {
println("Hello, MO 2016!")
}
6
val from_value : Type
var from_variable : Type
val i_am_string = “mobile”
var i_am_long = 666L
val i_am_double = 3.14e10
7
val & var
Null Safety
// can’t be null

val foo: String = “mobile”


// need always perform the check 

val bar: String? = null
8
Type? = Type or null
Null Safety
val bar: String? = “mobile”


var a = bar?.length // 6



var b = bar?.length?.inc() // 7



var c = bar!!.length // can be NPE
9
Null Safety
val bar: String? = null


var a = if (bar != null) bar.length

else 0 // 0



var b = bar?.length ?: 0 // 0

10
Type Definition
class Phone(val brand: String)
11
• concise syntax for constructor
• properties – not fields
• final by default. Use open to open
• simple old java class under the hood
Type Definition
class Phone(val brand: String){
var version: Int = 0
}
12
get() {…}

private set
val phone = Phone(“Apple”)

phone.brand == “Apple” // true
Value Object
data class Phone(val brand: String)
13
Lombok – no more
Get ready to be inspired
14
Delegates
15
class Foo<T> : List<T> {
private val innerList = arrayListOf<T>()
override val size: Int get() = innerList.size
override fun isEmpty() = innerList.isEmpty()
…

…
…
}
Delegates – right way
16
class Foo<T>
( innerList : List<T> = ArrayList<T>() )
: List<T> by innerList
All functions invocation delegated to innerList
Delegates – right way
17
class View {















}
val lazyProp by lazy { “mobile” }
val ops by observable(“”) { 

prop, old, new ->
print("$old to $new")
}
Delegates – wow way
18
class Activity {













}
private val btn: Button by lazy {

findViewById(R.id.btn) as Button

}



override fun onCreate(savedBundle: Bundle?) {

btn.setText(“Optimize!”)

}


Delegates – wow way
19
class SMS(val props: Map<String, String>) {



}
val date by props

val address by props



val info: String

get() {

“$date - $address” 

}
Delegates – wow way
20
class SMS(val props: Map<String, String>) {



}
val date by props

val address by props

…

val props = mapOf(“date” to “128932”,

“address” to “Sweden”)

val sms = SMS(props)
print(sms.info) // “128932 - Sweden”

Get ready to be inspired
21
Extensions
22
// Example



“Mobile”.lastChar() // “e”

// Definition



fun String.lastChar():Char 

= this.get(length - 1)
Extensions
23
// Java under the hood



@file:JvmName(“StringUtils")

StringUtils.lastChar(“Mobile”);
Extensions
24
Collections.max(list)



↓
list.max()
Extensions
25
operator fun BigDecimal.inc() 

= this + BigDecimal.ONE


// Example

var counter = BigDecimal.ZERO



print(++counter) // 1
Fun
26
Named Parameters
// Bad

ContentResolver.query(URI, new String[]{ },

null, null, null);
// Good

ContentResolver.query(URI, 

projection = new String[]{ },

selection = null,

selectionArgs = null,

sortOrder = null)
Fun
27
Named Parameters & Default Values
// Bad

IN_PROGRESS(true, false, false, false, false, false),

FAILED (false, true, true, false, false, false),

COMPLETE (true, false, true, false, false, true)



// Good

COMPLETE(stop = true, 

cancel = true, 

disable = true)

Fun
28
Named Parameters & Default Values
// Awesome



class COMPLETE(

stop: Boolean = false,

cancel: Boolean = false,

…

…)
Lambdas
29
val boys = listOf(

Boy(“Alex”), Boy(“Magnus”), Boy(“Nils”))

// 1 

boys.filter({ b: Boy -> b.age > 18 })

// 2

boys.filter({ it.age > 18 })


// 3

boys.filter { it.age > 18 }
λ
30
boys.filter { it.age > 18 }
.map { Pair(it, Boy("Eugene")) }
.forEach { dance(it) }
// Under the hood



inline fun <T> Iterable<T>.filter

(predicate: (T) -> Boolean)

DSL
31
• Type-safe
• Express your code by flexible syntax
• Ideal to build own query engine
• if/for/when just inside DSL
DSL
32
"(#C1 = :active) AND (#C2 = :type) AND " +
"(attribute_not_exists(#C1) OR #C1 IN
(:model, :allModels)) AND " +

"...";

if (smth)

append("(#C2 = :active) AND NOT
contains(#C3, :brandAll)");
…
// wait, oh shi~
DSL
33
val expr = filterExpr {

group {

eq("#1", ":2") and eq("#1", ":2") 

or group {

eq("#2", ":2")

if (smth) { 

and eq("#2", ":2") 

}

}

and ……

}
One more DSL thing
34
Gradle meets Kotlin
Kotlin 1.1
• Direct Java 8/9 support
• Type aliases
• Delegated properties everywhere
• Coroutines with async/await
35
bit.ly/kotlin_11
Kotlin 1.1
typealias Callback<T> = (T) -> T
// And now

fun alias(cb: Callback<String>) {}
36
Type aliases
Kotlin 1.1
typealias Table<K> = 

MutableMap<K,MutableList<String>>
37
Type aliases
Kotlin 1.1
fun (cb: Callback<String>) {



val callonce by lazy { cb("MO 2016") }
println(callonce)
}
38
Local delegated properties
Kotlin 1.1
val future = async<String> {
(1..5).map {
await(loooongAsyncOperation(it))



}.joinToString("n")
}
39
Coroutines with async/await
Kotlin friends
40
jprof.by
Belarus Kotlin User Group
bkug.by
Links
Awesome Kotlin kotlin.link
Slack kotlinlang.slack.com 

Local Chat gitter.im/JavaBy/Kotlin

41
Start your journey
with
42
twitter: @a_lithium

More Related Content

What's hot

Kotlin Backstage
Kotlin BackstageKotlin Backstage
Kotlin Backstage
Mitchell Tilbrook
 
C++ Programming - 5th Study
C++ Programming - 5th StudyC++ Programming - 5th Study
C++ Programming - 5th Study
Chris Ohk
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
Hassan Abid
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
Noritada Shimizu
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
akaptur
 
dplyr
dplyrdplyr
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
osfameron
 
A practical introduction to Kotlin
A practical introduction to KotlinA practical introduction to Kotlin
A practical introduction to Kotlin
Stathis Souris
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
Halil Özcan
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
Vikas Sharma
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
FDConf
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
Lorenz Cuno Klopfenstein
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Sway Wang
 
Grokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascriptGrokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascript
Grokking VN
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using Scala
Siarhiej Siemianchuk
 
Fractal proj report 2
Fractal proj report 2Fractal proj report 2
Fractal proj report 2
rpiitcbme
 
Git avançado
Git avançadoGit avançado
Git avançado
Jean Carlo Machado
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
Teppei Sato
 
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
tdc-globalcode
 

What's hot (20)

Kotlin Backstage
Kotlin BackstageKotlin Backstage
Kotlin Backstage
 
C++ Programming - 5th Study
C++ Programming - 5th StudyC++ Programming - 5th Study
C++ Programming - 5th Study
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
dplyr
dplyrdplyr
dplyr
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
A practical introduction to Kotlin
A practical introduction to KotlinA practical introduction to Kotlin
A practical introduction to Kotlin
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Grokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascriptGrokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascript
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using Scala
 
Fractal proj report 2
Fractal proj report 2Fractal proj report 2
Fractal proj report 2
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
 
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Android How we figured out we had a SRE team at ...
 

Viewers also liked

「RAD Studioアプリケーションとバックエンドシステムを接続する」
「RAD Studioアプリケーションとバックエンドシステムを接続する」「RAD Studioアプリケーションとバックエンドシステムを接続する」
「RAD Studioアプリケーションとバックエンドシステムを接続する」
Embarcadero Technologies
 
Clasificacion de los triangulos
Clasificacion de los triangulosClasificacion de los triangulos
Clasificacion de los triangulos
Jhon Adrian Huaman Mendoza
 
Preparing your B2B Site for Marketing Automation
Preparing your B2B Site for Marketing AutomationPreparing your B2B Site for Marketing Automation
Preparing your B2B Site for Marketing Automation
Profitable Conversions
 
Fitxes Mercè per Alumnat Nouvingut.
Fitxes Mercè per Alumnat Nouvingut.Fitxes Mercè per Alumnat Nouvingut.
Fitxes Mercè per Alumnat Nouvingut.
mpere334
 
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
Embarcadero Technologies
 
ShirleyZabalaMapaConceptual
ShirleyZabalaMapaConceptualShirleyZabalaMapaConceptual
ShirleyZabalaMapaConceptual
sid_phillips
 
Acondroplasia. atención primaria.
Acondroplasia. atención primaria.Acondroplasia. atención primaria.
Acondroplasia. atención primaria.
José María
 
Discapacidad intelectual y bienestar social.
Discapacidad intelectual y bienestar social.Discapacidad intelectual y bienestar social.
Discapacidad intelectual y bienestar social.
José María
 
Mandalas para la paz
Mandalas para la pazMandalas para la paz
Mandalas para la paz
cbcv
 
Los aceleradores de partíuclas y el lhc
Los aceleradores de partíuclas y el lhcLos aceleradores de partíuclas y el lhc
Los aceleradores de partíuclas y el lhc
nuriainformatica
 
Ortho discuss-spine fx
Ortho discuss-spine fxOrtho discuss-spine fx
Ortho discuss-spine fx
chittranoot liwluck
 
ATS-Catalogue-Latest
ATS-Catalogue-LatestATS-Catalogue-Latest
ATS-Catalogue-Latest
Lucky India Power Solutions
 
Creative Mornings San Diego 2016
Creative Mornings San Diego 2016Creative Mornings San Diego 2016
Creative Mornings San Diego 2016
Anne McColl
 

Viewers also liked (13)

「RAD Studioアプリケーションとバックエンドシステムを接続する」
「RAD Studioアプリケーションとバックエンドシステムを接続する」「RAD Studioアプリケーションとバックエンドシステムを接続する」
「RAD Studioアプリケーションとバックエンドシステムを接続する」
 
Clasificacion de los triangulos
Clasificacion de los triangulosClasificacion de los triangulos
Clasificacion de los triangulos
 
Preparing your B2B Site for Marketing Automation
Preparing your B2B Site for Marketing AutomationPreparing your B2B Site for Marketing Automation
Preparing your B2B Site for Marketing Automation
 
Fitxes Mercè per Alumnat Nouvingut.
Fitxes Mercè per Alumnat Nouvingut.Fitxes Mercè per Alumnat Nouvingut.
Fitxes Mercè per Alumnat Nouvingut.
 
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
「RAD Studio 10.1 Berlinで始めるIoTアプリケーション構築」
 
ShirleyZabalaMapaConceptual
ShirleyZabalaMapaConceptualShirleyZabalaMapaConceptual
ShirleyZabalaMapaConceptual
 
Acondroplasia. atención primaria.
Acondroplasia. atención primaria.Acondroplasia. atención primaria.
Acondroplasia. atención primaria.
 
Discapacidad intelectual y bienestar social.
Discapacidad intelectual y bienestar social.Discapacidad intelectual y bienestar social.
Discapacidad intelectual y bienestar social.
 
Mandalas para la paz
Mandalas para la pazMandalas para la paz
Mandalas para la paz
 
Los aceleradores de partíuclas y el lhc
Los aceleradores de partíuclas y el lhcLos aceleradores de partíuclas y el lhc
Los aceleradores de partíuclas y el lhc
 
Ortho discuss-spine fx
Ortho discuss-spine fxOrtho discuss-spine fx
Ortho discuss-spine fx
 
ATS-Catalogue-Latest
ATS-Catalogue-LatestATS-Catalogue-Latest
ATS-Catalogue-Latest
 
Creative Mornings San Diego 2016
Creative Mornings San Diego 2016Creative Mornings San Diego 2016
Creative Mornings San Diego 2016
 

Similar to Let's fly to the Kotlin Island. Just an introduction to Kotlin

Kotlin
KotlinKotlin
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
ThomasHorta
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Lorenzo Dematté
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
Cody Engel
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
Thijs Suijten
 
Criando app Android utilizando Kotlin
Criando app Android utilizando KotlinCriando app Android utilizando Kotlin
Criando app Android utilizando Kotlin
Luiz Henrique Santana
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Codemotion
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
Deepanshu Madan
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
Andrey Breslav
 
Kotlin Starter Pack
Kotlin Starter PackKotlin Starter Pack
Kotlin Starter Pack
Jimmy Morales
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
William Narmontas
 
Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011
Andrey Breslav
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
Ashal aka JOKER
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About Kotlin
Marco Vasapollo
 
XKE Typeclass
XKE TypeclassXKE Typeclass
XKE Typeclass
Mathieu DULAC
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 

Similar to Let's fly to the Kotlin Island. Just an introduction to Kotlin (20)

Kotlin
KotlinKotlin
Kotlin
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 
Criando app Android utilizando Kotlin
Criando app Android utilizando KotlinCriando app Android utilizando Kotlin
Criando app Android utilizando Kotlin
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
 
Kotlin Starter Pack
Kotlin Starter PackKotlin Starter Pack
Kotlin Starter Pack
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About Kotlin
 
XKE Typeclass
XKE TypeclassXKE Typeclass
XKE Typeclass
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 

Recently uploaded

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 

Recently uploaded (20)

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 

Let's fly to the Kotlin Island. Just an introduction to Kotlin

  • 1. Let’s fly to the Kotlin island short and comprehensive introduction Aliaksei Zhynhiarouski 1
  • 4. Why is Kotlin • Static Typing • Java + Kotlin = ❤. 
 Effortless mixing both in one project • Java Interoperability. 
 100% interoperable with Java. 4
  • 5. Why is Kotlin • Null Safety • Type Inference • Immutability in the mind • fun 5
  • 6. fun main(args : Array<String>) { println("Hello, MO 2016!") } 6
  • 7. val from_value : Type var from_variable : Type val i_am_string = “mobile” var i_am_long = 666L val i_am_double = 3.14e10 7 val & var
  • 8. Null Safety // can’t be null
 val foo: String = “mobile” 
 // need always perform the check 
 val bar: String? = null 8 Type? = Type or null
  • 9. Null Safety val bar: String? = “mobile” 
 var a = bar?.length // 6
 
 var b = bar?.length?.inc() // 7
 
 var c = bar!!.length // can be NPE 9
  • 10. Null Safety val bar: String? = null 
 var a = if (bar != null) bar.length
 else 0 // 0
 
 var b = bar?.length ?: 0 // 0
 10
  • 11. Type Definition class Phone(val brand: String) 11 • concise syntax for constructor • properties – not fields • final by default. Use open to open • simple old java class under the hood
  • 12. Type Definition class Phone(val brand: String){ var version: Int = 0 } 12 get() {…}
 private set val phone = Phone(“Apple”)
 phone.brand == “Apple” // true
  • 13. Value Object data class Phone(val brand: String) 13 Lombok – no more
  • 14. Get ready to be inspired 14
  • 15. Delegates 15 class Foo<T> : List<T> { private val innerList = arrayListOf<T>() override val size: Int get() = innerList.size override fun isEmpty() = innerList.isEmpty() …
 … … }
  • 16. Delegates – right way 16 class Foo<T> ( innerList : List<T> = ArrayList<T>() ) : List<T> by innerList All functions invocation delegated to innerList
  • 17. Delegates – right way 17 class View {
 
 
 
 
 
 
 
 } val lazyProp by lazy { “mobile” } val ops by observable(“”) { 
 prop, old, new -> print("$old to $new") }
  • 18. Delegates – wow way 18 class Activity {
 
 
 
 
 
 
 } private val btn: Button by lazy {
 findViewById(R.id.btn) as Button
 }
 
 override fun onCreate(savedBundle: Bundle?) {
 btn.setText(“Optimize!”)
 } 

  • 19. Delegates – wow way 19 class SMS(val props: Map<String, String>) {
 
 } val date by props
 val address by props
 
 val info: String
 get() {
 “$date - $address” 
 }
  • 20. Delegates – wow way 20 class SMS(val props: Map<String, String>) {
 
 } val date by props
 val address by props
 …
 val props = mapOf(“date” to “128932”,
 “address” to “Sweden”)
 val sms = SMS(props) print(sms.info) // “128932 - Sweden”

  • 21. Get ready to be inspired 21
  • 22. Extensions 22 // Example
 
 “Mobile”.lastChar() // “e”
 // Definition
 
 fun String.lastChar():Char 
 = this.get(length - 1)
  • 23. Extensions 23 // Java under the hood
 
 @file:JvmName(“StringUtils")
 StringUtils.lastChar(“Mobile”);
  • 25. Extensions 25 operator fun BigDecimal.inc() 
 = this + BigDecimal.ONE 
 // Example
 var counter = BigDecimal.ZERO
 
 print(++counter) // 1
  • 26. Fun 26 Named Parameters // Bad
 ContentResolver.query(URI, new String[]{ },
 null, null, null); // Good
 ContentResolver.query(URI, 
 projection = new String[]{ },
 selection = null,
 selectionArgs = null,
 sortOrder = null)
  • 27. Fun 27 Named Parameters & Default Values // Bad
 IN_PROGRESS(true, false, false, false, false, false),
 FAILED (false, true, true, false, false, false),
 COMPLETE (true, false, true, false, false, true)
 
 // Good
 COMPLETE(stop = true, 
 cancel = true, 
 disable = true)

  • 28. Fun 28 Named Parameters & Default Values // Awesome
 
 class COMPLETE(
 stop: Boolean = false,
 cancel: Boolean = false,
 …
 …)
  • 29. Lambdas 29 val boys = listOf(
 Boy(“Alex”), Boy(“Magnus”), Boy(“Nils”))
 // 1 
 boys.filter({ b: Boy -> b.age > 18 })
 // 2
 boys.filter({ it.age > 18 }) 
 // 3
 boys.filter { it.age > 18 }
  • 30. λ 30 boys.filter { it.age > 18 } .map { Pair(it, Boy("Eugene")) } .forEach { dance(it) } // Under the hood
 
 inline fun <T> Iterable<T>.filter
 (predicate: (T) -> Boolean)

  • 31. DSL 31 • Type-safe • Express your code by flexible syntax • Ideal to build own query engine • if/for/when just inside DSL
  • 32. DSL 32 "(#C1 = :active) AND (#C2 = :type) AND " + "(attribute_not_exists(#C1) OR #C1 IN (:model, :allModels)) AND " +
 "...";
 if (smth)
 append("(#C2 = :active) AND NOT contains(#C3, :brandAll)"); … // wait, oh shi~
  • 33. DSL 33 val expr = filterExpr {
 group {
 eq("#1", ":2") and eq("#1", ":2") 
 or group {
 eq("#2", ":2")
 if (smth) { 
 and eq("#2", ":2") 
 }
 }
 and ……
 }
  • 34. One more DSL thing 34 Gradle meets Kotlin
  • 35. Kotlin 1.1 • Direct Java 8/9 support • Type aliases • Delegated properties everywhere • Coroutines with async/await 35 bit.ly/kotlin_11
  • 36. Kotlin 1.1 typealias Callback<T> = (T) -> T // And now
 fun alias(cb: Callback<String>) {} 36 Type aliases
  • 37. Kotlin 1.1 typealias Table<K> = 
 MutableMap<K,MutableList<String>> 37 Type aliases
  • 38. Kotlin 1.1 fun (cb: Callback<String>) {
 
 val callonce by lazy { cb("MO 2016") } println(callonce) } 38 Local delegated properties
  • 39. Kotlin 1.1 val future = async<String> { (1..5).map { await(loooongAsyncOperation(it))
 
 }.joinToString("n") } 39 Coroutines with async/await