SlideShare a Scribd company logo
1 of 59
Download to read offline
Develop your next app with
Kotlin
@arnogiu
Work @ ekito
Core & Gear Maker
Mobile & CloudArnaud GIULIANI
« production ready »
15.02.2016
1.1.1 @ 15.03.2017
Yet another JVM
Language ?
The new « Swift »
for Android ?
https://goo.gl/W5g6Do - mid 2014
Limits of java
- Verbose
- Type inference
- No properties / Lazy / Delegate
- Checked exception
- NullPointerException
- Extensibility
- End of lines with ;
@
sdeleuze
But Java is great …
- Fast
- Optimized bytecode
- Static typing
- Simple to learn
- Amazing ecosystem
- Conciseness & Smarter API
- Null Safety & Immutability protection
- Type Inference, Static Typing & Smart Casts
- Open programming styles
- Java Interop
Why
Kotlin ?
What’s
Kotlin ?
- Fully open source (built by Jetbrains)
- Based on Java & run on Java 6+
- Modern language features
- 1st grade tooling
More About
Kotlin …
- String templates
- Properties
- Lambdas
- Data class
- Smart cast
- Null safety
- Lazy property
- Default values for function
parameters
- Extension Functions
- No more ;
- Single-expression
functions
- When expression
- let, apply, use, with
- Collections
- Android Extensions Plugin
Compare with
Same conciseness and expressive code, but
Kotlin static typing and null-safety make a big
difference.
"Some people say Kotlin has 80% the power of
Scala, with 20% of the features" * 

"Kotlin is a software engineering language in
contrast to Scala which is a computing science
language." *
Swift and Kotlin are VERY similar. Swift is LLVM
based and has C interop while Kotlin is JVM based
and has Java interop.
* Quotes from Kotlin:TheYing andYang of Programming Languages
@
sdeleuze
is Kotlin Android friendly ?
https://github.com/SidneyXu/AndroidDemoIn4Languages
Method counts by Language
Java 8 on
Android ?
https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html
KOTLIN is not just about writing
your app with lesser lines.
It’s all about writing
SAFER & BETTER APPS !
Kotlin clearly considered
by the Java community !
https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-
spring-framework-5-0
http://www.javamagazine.mozaicreader.com/
#&pageSet=5&page=0&contentItem=0 (March/April
2017)
https://www.thoughtworks.com/radar/languages-and-frameworks/kotlin
Ready to use
Easy to run
Getting started with
gradle
buildscript {
ext.kotlin_version = '<version to use>'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
Gradle tips for Kotlin
# Gradle

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:
+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

org.gradle.parallel=true
org.gradle.deamon=true



# Kotlin

kotlin.incremental=true



# Android Studio 2.2+

android.enableBuildCache=true
In your gradle.properties
https://medium.com/keepsafe-engineering/kotlin-vs-java-compilation-speed-e6c174b39b5d#.k44v7axsk
Let’s go !
Typing & Inference
val a: Int = 1

val b = 1 // `Int` type is inferred
var x = 5 // `Int` type is inferred

x += 1
Inferred values
Mutable values
val : constant value - IMMUTABLE
var : variable value - MUTABLE
USE VAL AS MUCH AS POSSIBLE !
Safety with Optionals
var stringA: String = "foo"

stringA = null //Compilation error - stringA is a String (non optional)



var stringB: String? = "bar" // stringB is an Optional String

stringB = null //ok
Optional value with ?
// set length default value manually

val length = if (stringB != null) stringB.length else -1

//or with the Elvis operator

val length = stringB?.length ?: -1
DefaultValue & Elvis Operator :?
val length = stringB.length // Compilation error - stringB can be null !

// use ? the safe call operator

val length = stringB?.length //Value or null - length is type Int?
val length = stringB!!.length //Value or explicit throw NPE - length is type Int
Safe call with ?. or Explicit call with !!.
Example
Working with optional values
Example
Null check safety & Smart cast
Securing with default values
Class
class User (

val userName: String,

val firstName: String,

val lastName: String,

var location: Point? = null

)
POJO +
- Getter
- Setter
- Constructors
Data Class
data class User (

val userName: String,

val firstName: String,

val lastName: String,

var location: Point? = null

)
POJO +
- Getter
- Setter
- Constructors
- toString
- hashcode
- equals
- copy
POJO ?
Kotlin
Java
Properties
// readonly property

val isEmpty: Boolean

get() = this.size == 0
Properties can be declared in constructor or in class
You can also handle getter & setter
lateinit var weatherWS :WeatherWS



@Test

fun testMyWeatherWS() {

weatherWS = Inject.get<WeatherWS>()

// ... 

}
class ApiKey(var weatherKey: String, var geocodeKey: String){

var debug : Boolean = false

}
Late & Lazy initialization
Example
data class User(val name: String = "", val age: Int = 0)
val jack = User(name = "Jack", age = 1) //no new keyword

val anotherJack = jack.copy(age = 2)
Data Class usage
A simple GSon Class
Object Class
// singleton

object Resource {

val name = "Name"

}
class StringCalculator{
// class helper

companion object{

val operators = arrayOf("+","-","x","/")

}

}
Singleton Class
Companion Object
When
when (s) {

1 -> print("x == 1")

2 -> print("x == 2")

else -> { // Note the block

print("x is neither 1 nor 2")

}

}
Flow Control (replace your switch and if-blocks)
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")

}
Pattern Matching
Example
Page Adapter
Menu Select
Collections
// immutable map

val map = mapOf("a" to 1, "b" to 2, "c" to 3)

for ((k, v) in map) {

println("$k -> $v")

}


map["a"] = "my value" // direct map access with array style
// range

for (i in 1..100) { //... }
// immutable list

val list = listOf("a", "b", "c","aa")

list.filter { it.startsWith("a") }
* collections operators : map, filter, take, flatMap, forEach, firstOrNull, last …
Example
Kotlin Collection
Java 7 Collection
Lambdas
val fab = findViewById(R.id.fab) as FloatingActionButton

fab.setOnClickListener { view -> popLocationDialog(view) }
A lambda expression or an anonymous function is a “function literal”, i.e. a function that is
not declared, but passed immediately as an expression
- A lambda expression is always surrounded by curly braces
- Its parameters (if any) are declared before -> (parameter types may be omitted),
- The body goes after -> (when present).
myNumber.split("n").flatMap { it.split(separator) }

.map(Integer::parseInt)

.map(::checkPositiveNumber)

.filter { it <= 1000 }

.sum()
* Method references are not surrounded by curly braces !
Functions
fun reformat(str: String,

normalizeCase: Boolean = true,

upperCaseFirstLetter: Boolean = true,

wordSeparator: Char = ' '): String {



}
Named Parameters & default values
reformat(str, true, true, '_') // old way to call

reformat(str, wordSeparator = '_') // using default values & named params
Extensions Functions
Extension declaration
Usage
Destructuring Declarations
In lambdas, Since Kotlin 1.1
map.mapValues { (key, value) -> "$value!" }
Destructured variables declaration
val person = Person("john",31) //data class Person(val name:String, val age : Int)

val (name,age) = person

println("I'm $name, my age is $age")
* Works with Map, Data Class, Pair,Triple …
=> you can return 2 values in function !
InterOp Kotlin/Java
Java
Kotlin
InterOp Java/Kotlin
object UserSingleton{

fun stringify(user : User) : String{

// …

}

}
fun WhatIsyourAge(user : User){

println("Your age is ${user.age}")

}
data class User (val name: String, val age : Int){

companion object{

fun sayHello(user : User){
//…

}

}

}
User u = new User("toto",42);

User.Companion.sayHello(u);
UserUtilsKt.WhatIsyourAge(u);
UserSingleton.INSTANCE.stringify(u)
Sweet stuffs for
Kotlin’s Android
Extensions
apply plugin: 'com.android.application'
apply plugin:‘kotlin-android’
apply plugin:‘kotlin-android-extensions’ // the kotlin-android extension !
In your build.gradle
Kotlin
Java
Reactive
Programming
Lamba expressions
Functional Programming
Reactive Streams
http://reactivex.io/documentation/operators.html
http://www.reactive-streams.org/
https://spring.io/blog/2016/06/07/notes-on-reactive-
programming-part-i-the-reactive-landscape
Example - Rx/Retrofit
Kotlin
Java 7
Example - Rx/Realm
Load first element & update UI
50
Ready to Go ?
51
Just another hype
JVM stuff ?
52
Production
ready ?
It’s always hard to start !
Our feedback
- Easy to start on existing project
- Great learning curve
- Good doc & tools support
- Don’t use anymore Butterknife, Dagger …
- T_T hard to come back to Java
https://www.ekito.fr/people/kotlin-in-production-one-year-later/
IF YOU DON'T LOOK AT
JAVA AND THINK, "THIS
COULD BE BETTER", DON'T
SWITCH.
@RunChristinaRun (Pinterest)
Try Kotlin online
http://try.kotlinlang.org/#/Examples/
Kotlin Reference
https://kotlinlang.org/docs/reference/
Kotlin Cheat Sheet (by ekito)
https://speakerdeck.com/agiuliani/kotlin-cheat-
sheet
70% Less !
Develop a
weather app with K
https://github.com/Ekito/2017-handson-kotlinAndroid
Thank you :)

More Related Content

What's hot

Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyHaim Yadid
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivitynklmish
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan s.r.o.
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaVasil Remeniuk
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlinThijs Suijten
 

What's hot (19)

Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana Isakova
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 

Similar to Develop your next app with Kotlin

Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers STX Next
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?reallavalamp
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехСбертех | SberTech
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaOstap Andrusiv
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresA TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresGarth Gilmour
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 

Similar to Develop your next app with Kotlin (20)

Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?How Does Kubernetes Build OpenAPI Specifications?
How Does Kubernetes Build OpenAPI Specifications?
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresA TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS Adventures
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 

Recently uploaded

George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 

Recently uploaded (20)

George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 

Develop your next app with Kotlin

  • 1. Develop your next app with Kotlin
  • 2. @arnogiu Work @ ekito Core & Gear Maker Mobile & CloudArnaud GIULIANI
  • 6. The new « Swift » for Android ? https://goo.gl/W5g6Do - mid 2014
  • 7. Limits of java - Verbose - Type inference - No properties / Lazy / Delegate - Checked exception - NullPointerException - Extensibility - End of lines with ; @ sdeleuze
  • 8. But Java is great … - Fast - Optimized bytecode - Static typing - Simple to learn - Amazing ecosystem
  • 9.
  • 10. - Conciseness & Smarter API - Null Safety & Immutability protection - Type Inference, Static Typing & Smart Casts - Open programming styles - Java Interop Why Kotlin ?
  • 11. What’s Kotlin ? - Fully open source (built by Jetbrains) - Based on Java & run on Java 6+ - Modern language features - 1st grade tooling
  • 12. More About Kotlin … - String templates - Properties - Lambdas - Data class - Smart cast - Null safety - Lazy property - Default values for function parameters - Extension Functions - No more ; - Single-expression functions - When expression - let, apply, use, with - Collections - Android Extensions Plugin
  • 13. Compare with Same conciseness and expressive code, but Kotlin static typing and null-safety make a big difference. "Some people say Kotlin has 80% the power of Scala, with 20% of the features" * 
 "Kotlin is a software engineering language in contrast to Scala which is a computing science language." * Swift and Kotlin are VERY similar. Swift is LLVM based and has C interop while Kotlin is JVM based and has Java interop. * Quotes from Kotlin:TheYing andYang of Programming Languages @ sdeleuze
  • 14. is Kotlin Android friendly ? https://github.com/SidneyXu/AndroidDemoIn4Languages Method counts by Language
  • 15. Java 8 on Android ? https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html
  • 16. KOTLIN is not just about writing your app with lesser lines. It’s all about writing SAFER & BETTER APPS !
  • 17. Kotlin clearly considered by the Java community ! https://spring.io/blog/2017/01/04/introducing-kotlin-support-in- spring-framework-5-0 http://www.javamagazine.mozaicreader.com/ #&pageSet=5&page=0&contentItem=0 (March/April 2017) https://www.thoughtworks.com/radar/languages-and-frameworks/kotlin
  • 19. Getting started with gradle buildscript { ext.kotlin_version = '<version to use>' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: "kotlin" dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }
  • 20. Gradle tips for Kotlin # Gradle
 org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX: +HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
 org.gradle.parallel=true org.gradle.deamon=true
 
 # Kotlin
 kotlin.incremental=true
 
 # Android Studio 2.2+
 android.enableBuildCache=true In your gradle.properties https://medium.com/keepsafe-engineering/kotlin-vs-java-compilation-speed-e6c174b39b5d#.k44v7axsk
  • 22. Typing & Inference val a: Int = 1
 val b = 1 // `Int` type is inferred var x = 5 // `Int` type is inferred
 x += 1 Inferred values Mutable values val : constant value - IMMUTABLE var : variable value - MUTABLE USE VAL AS MUCH AS POSSIBLE !
  • 23. Safety with Optionals var stringA: String = "foo"
 stringA = null //Compilation error - stringA is a String (non optional)
 
 var stringB: String? = "bar" // stringB is an Optional String
 stringB = null //ok Optional value with ?
  • 24. // set length default value manually
 val length = if (stringB != null) stringB.length else -1
 //or with the Elvis operator
 val length = stringB?.length ?: -1 DefaultValue & Elvis Operator :? val length = stringB.length // Compilation error - stringB can be null !
 // use ? the safe call operator
 val length = stringB?.length //Value or null - length is type Int? val length = stringB!!.length //Value or explicit throw NPE - length is type Int Safe call with ?. or Explicit call with !!.
  • 26. Example Null check safety & Smart cast Securing with default values
  • 27. Class class User (
 val userName: String,
 val firstName: String,
 val lastName: String,
 var location: Point? = null
 ) POJO + - Getter - Setter - Constructors
  • 28. Data Class data class User (
 val userName: String,
 val firstName: String,
 val lastName: String,
 var location: Point? = null
 ) POJO + - Getter - Setter - Constructors - toString - hashcode - equals - copy
  • 30. Properties // readonly property
 val isEmpty: Boolean
 get() = this.size == 0 Properties can be declared in constructor or in class You can also handle getter & setter lateinit var weatherWS :WeatherWS
 
 @Test
 fun testMyWeatherWS() {
 weatherWS = Inject.get<WeatherWS>()
 // ... 
 } class ApiKey(var weatherKey: String, var geocodeKey: String){
 var debug : Boolean = false
 } Late & Lazy initialization
  • 31. Example data class User(val name: String = "", val age: Int = 0) val jack = User(name = "Jack", age = 1) //no new keyword
 val anotherJack = jack.copy(age = 2) Data Class usage A simple GSon Class
  • 32. Object Class // singleton
 object Resource {
 val name = "Name"
 } class StringCalculator{ // class helper
 companion object{
 val operators = arrayOf("+","-","x","/")
 }
 } Singleton Class Companion Object
  • 33. When when (s) {
 1 -> print("x == 1")
 2 -> print("x == 2")
 else -> { // Note the block
 print("x is neither 1 nor 2")
 }
 } Flow Control (replace your switch and if-blocks) 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")
 } Pattern Matching
  • 35. Collections // immutable map
 val map = mapOf("a" to 1, "b" to 2, "c" to 3)
 for ((k, v) in map) {
 println("$k -> $v")
 } 
 map["a"] = "my value" // direct map access with array style // range
 for (i in 1..100) { //... } // immutable list
 val list = listOf("a", "b", "c","aa")
 list.filter { it.startsWith("a") } * collections operators : map, filter, take, flatMap, forEach, firstOrNull, last …
  • 37. Lambdas val fab = findViewById(R.id.fab) as FloatingActionButton
 fab.setOnClickListener { view -> popLocationDialog(view) } A lambda expression or an anonymous function is a “function literal”, i.e. a function that is not declared, but passed immediately as an expression - A lambda expression is always surrounded by curly braces - Its parameters (if any) are declared before -> (parameter types may be omitted), - The body goes after -> (when present). myNumber.split("n").flatMap { it.split(separator) }
 .map(Integer::parseInt)
 .map(::checkPositiveNumber)
 .filter { it <= 1000 }
 .sum() * Method references are not surrounded by curly braces !
  • 38. Functions fun reformat(str: String,
 normalizeCase: Boolean = true,
 upperCaseFirstLetter: Boolean = true,
 wordSeparator: Char = ' '): String {
 
 } Named Parameters & default values reformat(str, true, true, '_') // old way to call
 reformat(str, wordSeparator = '_') // using default values & named params
  • 40. Destructuring Declarations In lambdas, Since Kotlin 1.1 map.mapValues { (key, value) -> "$value!" } Destructured variables declaration val person = Person("john",31) //data class Person(val name:String, val age : Int)
 val (name,age) = person
 println("I'm $name, my age is $age") * Works with Map, Data Class, Pair,Triple … => you can return 2 values in function !
  • 42. InterOp Java/Kotlin object UserSingleton{
 fun stringify(user : User) : String{
 // …
 }
 } fun WhatIsyourAge(user : User){
 println("Your age is ${user.age}")
 } data class User (val name: String, val age : Int){
 companion object{
 fun sayHello(user : User){ //…
 }
 }
 } User u = new User("toto",42);
 User.Companion.sayHello(u); UserUtilsKt.WhatIsyourAge(u); UserSingleton.INSTANCE.stringify(u)
  • 44. Kotlin’s Android Extensions apply plugin: 'com.android.application' apply plugin:‘kotlin-android’ apply plugin:‘kotlin-android-extensions’ // the kotlin-android extension ! In your build.gradle
  • 47. Lamba expressions Functional Programming Reactive Streams http://reactivex.io/documentation/operators.html http://www.reactive-streams.org/ https://spring.io/blog/2016/06/07/notes-on-reactive- programming-part-i-the-reactive-landscape
  • 49. Example - Rx/Realm Load first element & update UI
  • 53. It’s always hard to start !
  • 54. Our feedback - Easy to start on existing project - Great learning curve - Good doc & tools support - Don’t use anymore Butterknife, Dagger … - T_T hard to come back to Java https://www.ekito.fr/people/kotlin-in-production-one-year-later/
  • 55. IF YOU DON'T LOOK AT JAVA AND THINK, "THIS COULD BE BETTER", DON'T SWITCH. @RunChristinaRun (Pinterest)
  • 56.
  • 57. Try Kotlin online http://try.kotlinlang.org/#/Examples/ Kotlin Reference https://kotlinlang.org/docs/reference/ Kotlin Cheat Sheet (by ekito) https://speakerdeck.com/agiuliani/kotlin-cheat- sheet
  • 58. 70% Less ! Develop a weather app with K https://github.com/Ekito/2017-handson-kotlinAndroid