SlideShare a Scribd company logo
Introduction to Kotlin language & its
application to Android platform
Overview
What is Kotlin
• Kotlin is a new programming language by Jetbrains.
• It runs on JVM stack.
• It has ≈zero-cost Java interop.
• It runs on Android, easily.
Let’s go!
• Kotlin is a new programming language by Jetbrains.
• It runs on JVM stack.
• It has ≈zero-cost Java interop.
• It runs on Android, easily.
Hello, world!
fun main(args: Array<String>) {
println("Hello, world!")
}
Hello, world!
fun main(args: Array<String>) =
println("Hello, world!")
Hello, world!
fun main(args: Array<String>) =
args.joinToString(postfix = "!")
.forEach { print(it) }
> kotlin HelloKt Hello world
Why Kotlin?
• Concise — write less boilerplate.
• Interoperable — write alongside your Java code.
• Multi-paradigm — you can write functional-alike code.
• Promising — developed by developers for developers.
• It runs on Android, easily!
Kotlin on Android
Why Kotlin?
• Android runs using fork of Apache Harmony (≈Java 6).
• Starting from Android API 19 (Android 4.4) it supports Java 7 features.
• Android N (Nutella? 6.1?) brings support for Java 8.
• But it is still Java…
Why Kotlin?
• There are lot of modern features and approaches that are unavailable
even in Java 8.
• Typical Java code is bloated, has a lot of boilerplate.
• Kotlin is much more expressive than Java.
Why Kotlin?
final Config config = playlist.getConfig();
if (config != null && config.getUrls() != null) {
for (final Url url : config.getUrls()) {
if (url.getFormat().equals("txt")) {
this.url = url;
}
}
}
Why Kotlin?
playlist.config?.urls
?.firstOrNull { it.format == "txt" }
?.let { this.url = it.url }
Kotlin features
Null safety
• You won’t see NPE anymore (unless you want)
• In pure Kotlin, you can have something non-null:
• var foo: String = "foo"
• Or nullable
• var bar: String? = "bar"
• Then:
• foo = null → compilation error
• bar = null → OK
Null safety
• var foo: String = "foo"
• var bar: String? = "bar"
• foo.length → 3
• bar.length → ???
Null safety
• var foo: String = "foo"
• var bar: String? = "bar"
• foo.length → 3
• bar.length → compilation error
• Call is null-unsafe, there are two methods to fix it:
• bar?.length → 3 (or null if bar == null)
• bar!!.length → 3 (or NPE if bar == null)
Null safety
• var foo: String = "foo"
• var bar: String? = "bar"
• if (bar != null) {
• // bar is effectively not null, it can be treated as String, not String?
• bar.length → 3
• }
Null safety
• Kotlin understands lot of Java annotations for null-safety (JSR-308,
Guava, Android, Jetbrains, etc.)
• If nothing is specified, you can treat Java object as Nullable
Null safety
• Kotlin understands lot of Java annotations for null-safety (JSR-308,
Guava, Android, Jetbrains, etc.)
• If nothing is specified, you can treat Java object as Nullable
• Or NotNull!
• It’s up to you, and you should take care of proper handling nulls.
Type inference
• var bar: CharSequence? = "bar"
• if (bar != null && bar is String) {
• // bar can be treated as String without implicit conversion
• bar.length → 3
• }
Type inference
• fun List.reversed() = Collections.reverse(list)
• Return type List is inferred automatically
• //effectively fun List.reversed() : List = Collections.reverse(list)
Lambdas
• Kotlin has it
• And it helps a lot
• Works fine for SAM
Lambdas
strings
.filter( { it.count { it in "aeiou" } >= 3 } )
.filterNot { it.contains("ab|cd|pq|xy".toRegex()) }
.filter { s -> s.contains("([a-z])1".toRegex()) }
.size.toString()
Lambdas
• Can be in-lined.
• Can use anonymous class if run on JVM 6.
• Can use native Java lambdas if run on JVM 8.
Expressivity
• new Foo() → foo()
• foo.bar(); → foo.bar()
• Arrays.asList("foo", "bar") → listOf("foo", "bar")
Collections operations
• Lot of functional-alike operations and possibilities.
• You don’t need to write loops anymore.
• Loops are not prohibited.
• We can have Streams on Java 6.
Lambdas
strings
.filter( { it.count { it in "aeiou" } >= 3 } )
.filterNot { it.contains("ab|cd|pq|xy".toRegex()) }
.filter { s -> s.contains("([a-z])1".toRegex()) }
.size.toString()
Java Beans, POJOs and so on
• Write fields
• Write constructors
• Write getters and setters
• Write equals() and hashCode()
• …
Properties
• var age: Int = 0
• Can be accessed as a field from Kotlin.
• Getters and setters are generated automatically for Java.
• If Java code has getters and setters, it can be accessed as property from
Kotlin
• Can be computed and even lazy
Data classes
• data class User(var name: String, var age: Int)
• Compiler generates getters and setters for Java interop
• Compiler generates equals() and hashCode()
• Compiler generates copy() method — flexible clone() replacement
Data classes
• data class User(val name: String, val age: Int)
• 5 times less LOC.
• No need to maintain methods consistency.
• No need to write builders and/or numerous constructors.
• Less tests to be written.
Data classes
• Model and ViewModel conversion to Kotlin
• Made automatically
• Was: 1750 LOC in 23 files
• Now: 800 LOC
• And lot of tests are now redundant!
Extension methods
• Usual Java project has 5-10 *Utils classes.
• Reasons:
• Some core/library classes are final
• Sometimes you don’t need inheritance
• Even standard routines are often wrapped with utility classes
• Collections.sort(list)
Extension methods
• You can define extension method
• fun List.sort()
• Effectively it’ll have the same access policies as your static methods in
*Utils
• But it can be called directly on instance!
• fun List.sort() = Collections.sort(this)
• someList.sort()
Extension methods
• You can handle even null instances:
fun String?.toast(context: Context) {
if (this != null) Toast.makeToast(context,
this, Toast.LENGTH_LONG).show()
}
String interpolation
• println("Hello, world!")
• println("Hello, $name!")
• println("Hello, ${name.toCamelCase()}!")
Anko
• DSL for Android
verticalLayout {
val name = editText()
button("Say Hello") {
onClick { toast("Hello, ${name.text}!") }
}
}
Anko
• DSL for Android.
• Shortcuts for widely used features (logging, intents, etc.).
• SQLite bindings.
• Easy (compared to core Android) async operations.
Useful libraries
• RxKotlin — FRP in Kotlin manner
• Spek — Unit tests (if we still need it)
• Kotlin Android extensions — built-it ButterKnife
• Kotson — Gson with Kotlin flavor
Summary
Cost of usage
Each respective use has a .class method cost of
• Java 6 anonymous class: 2
• Java 8 lambda: 1
• Java 8 lambda with Retrolambda: 6
• Java 8 method reference: 0
• Java 8 method reference with Retrolambda: 5
• Kotlin with Java Runnable expression: 3
• Kotlin with native function expression: 4
Cost of usage
• Kotlin stdlib contains ≈7K methods
• Some part of stdlib is going to be extracted and inlined compile-time
• And ProGuard strips unused methods just perfect
Build and tools
• Ant tasks, Maven and Gradle plugins
• Console compiler and REPL
• IntelliJ IDEA — out of the box
• Android Studio, other Jetbrains IDEs — as plugin
• Eclipse — plugin
Build and tools
• Can be compiled to run on JVM.
• Can be run using Jack (Java Android Compiler Kit)
• Can be compiled to JS.
• Can be used everywhere where Java is used.
Kotlin pros and cons
• It’s short and easy.
• It has zero-cost Java
interoperability.
• You’re not obliged to rewrite all
your code in Kotlin.
• You can apply modern approaches
(like FRP) without bloating your
code.
• And you could always go back to
Java (but you won’t).
• Longer compile time.
• Heavy resources usage.
• Some overhead caused by stdlib
included in dex file.
• Sometimes errors are cryptic.
• There are some bugs and issues in
language and tools.
• Community is not so huge as Java
one.
Useful Resources
Books
• Kotlin for Android Developers.
• The first (and only) book about Kotlin
• Regular updates with new language
features
• https://leanpub.com/kotlin-for-android-
developers
Books
• Kotlin in Action.
• A book by language authors
• WIP, 8/14 chapters are ready, available
for early access
• https://www.manning.com/books/kotlin-
in-action
Links
• https://kotlinlang.org — official site
• http://blog.jetbrains.com/kotlin/ — Jetbrains blog
• http://kotlinlang.slack.com/ + http://kotlinslackin.herokuapp.com/ —
community Slack channel
• https://www.reddit.com/r/Kotlin/ — subreddit
• https://github.com/JetBrains/kotlin — it’s open, yeah!
• https://kotlinlang.org/docs/tutorials/koans.html — simple tasks to get familiar
with language.
• http://try.kotlinlang.org — TRY IT, NOW!
THANK YOU
Oleg Godovykh
Software Engineer
oleg.godovykh@eastbanctech.com
202-295-3000
http://eastbanctech.com

More Related Content

What's hot (20)

PDF
Kotlin for Android Development
Speck&Tech
 
PPT
Groovy presentation
Manav Prasad
 
PDF
JUnit 5 - The Next Generation
Kostadin Golev
 
PDF
How to go about testing in React?
Lisa Gagarina
 
PPTX
Intro to kotlin
Tomislav Homan
 
PPTX
Android with kotlin course
Abdul Rahman Masri Attal
 
PPSX
Junit
FAROOK Samath
 
PPTX
Introduction to Koltin for Android Part I
Atif AbbAsi
 
PDF
Scalable JavaScript Application Architecture
Nicholas Zakas
 
PDF
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
PPTX
Introduction to Kotlin
T.M. Ishrak Hussain
 
PDF
Introduction to kotlin coroutines
NAVER Engineering
 
PPTX
Core java
Shubham singh
 
PPTX
Jetpack Compose.pptx
GDSCVJTI
 
PDF
An Abusive Relationship with AngularJS
Mario Heiderich
 
PPTX
JVM++: The Graal VM
Martin Toshev
 
PPTX
Testing of React JS app
Aleks Zinevych
 
PDF
Getting started with flutter
rihannakedy
 
PDF
Android Programming Basics
Eueung Mulyana
 
PPTX
Writing and using Hamcrest Matchers
Shai Yallin
 
Kotlin for Android Development
Speck&Tech
 
Groovy presentation
Manav Prasad
 
JUnit 5 - The Next Generation
Kostadin Golev
 
How to go about testing in React?
Lisa Gagarina
 
Intro to kotlin
Tomislav Homan
 
Android with kotlin course
Abdul Rahman Masri Attal
 
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Scalable JavaScript Application Architecture
Nicholas Zakas
 
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
Introduction to Kotlin
T.M. Ishrak Hussain
 
Introduction to kotlin coroutines
NAVER Engineering
 
Core java
Shubham singh
 
Jetpack Compose.pptx
GDSCVJTI
 
An Abusive Relationship with AngularJS
Mario Heiderich
 
JVM++: The Graal VM
Martin Toshev
 
Testing of React JS app
Aleks Zinevych
 
Getting started with flutter
rihannakedy
 
Android Programming Basics
Eueung Mulyana
 
Writing and using Hamcrest Matchers
Shai Yallin
 

Viewers also liked (6)

PDF
20111002 csseminar kotlin
Computer Science Club
 
PDF
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
Yandex
 
PDF
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
PDF
Swift and Kotlin Presentation
Andrzej Sitek
 
PPTX
Architecture iOS et Android
Hadina RIMTIC
 
PDF
Session 1 - Introduction to iOS 7 and SDK
Vu Tran Lam
 
20111002 csseminar kotlin
Computer Science Club
 
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
Yandex
 
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
Swift and Kotlin Presentation
Andrzej Sitek
 
Architecture iOS et Android
Hadina RIMTIC
 
Session 1 - Introduction to iOS 7 and SDK
Vu Tran Lam
 
Ad

Similar to Introduction to Kotlin Language and its application to Android platform (20)

PPTX
Kotlin – the future of android
DJ Rausch
 
PDF
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 
PDF
Little Helpers for Android Development with Kotlin
Kai Koenig
 
PDF
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
PDF
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
PPTX
Why kotlininandroid
Phani Kumar Gullapalli
 
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
PDF
9054799 dzone-refcard267-kotlin
Zoran Stanimirovic
 
PDF
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
PDF
Lightning talk: Kotlin
Evolve
 
PDF
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
PDF
Kotlin Introduction with Android applications
Thao Huynh Quang
 
PPTX
Kotlin - A Programming Language
Mobio Solutions
 
PDF
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
PDF
Summer of Tech 2017 - Kotlin/Android bootcamp
Kai Koenig
 
PDF
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
PPTX
Kotlin
Sudhanshu Vohra
 
PPTX
Intro to kotlin 2018
Shady Selim
 
PDF
What’s new in Kotlin?
Squareboat
 
PPTX
Introduction to Kotlin for Android developers
Mohamed Wael
 
Kotlin – the future of android
DJ Rausch
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 
Little Helpers for Android Development with Kotlin
Kai Koenig
 
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
Why kotlininandroid
Phani Kumar Gullapalli
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
9054799 dzone-refcard267-kotlin
Zoran Stanimirovic
 
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
Lightning talk: Kotlin
Evolve
 
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
Kotlin Introduction with Android applications
Thao Huynh Quang
 
Kotlin - A Programming Language
Mobio Solutions
 
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Kai Koenig
 
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
Intro to kotlin 2018
Shady Selim
 
What’s new in Kotlin?
Squareboat
 
Introduction to Kotlin for Android developers
Mohamed Wael
 
Ad

More from EastBanc Tachnologies (14)

PPTX
Unpacking .NET Core | EastBanc Technologies
EastBanc Tachnologies
 
PPTX
Azure and/or AWS: How to Choose the best cloud platform for your project
EastBanc Tachnologies
 
PPTX
Functional Programming with C#
EastBanc Tachnologies
 
PPTX
Getting started with azure event hubs and stream analytics services
EastBanc Tachnologies
 
PPTX
DevOps with Kubernetes
EastBanc Tachnologies
 
PPTX
Developing Cross-Platform Web Apps with ASP.NET Core1.0
EastBanc Tachnologies
 
PPTX
Highlights from MS build\\2016 Conference
EastBanc Tachnologies
 
PPTX
Estimating for Fixed Price Projects
EastBanc Tachnologies
 
PPTX
Async Programming with C#5: Basics and Pitfalls
EastBanc Tachnologies
 
PPTX
EastBanc Technologies US-Russian Collaboration and Innovation
EastBanc Tachnologies
 
PPTX
EastBanc Technologies SharePoint Portfolio
EastBanc Tachnologies
 
PDF
EastBanc Technologies Data Visualization/BI Portfolio
EastBanc Tachnologies
 
PDF
EastBanc Technologies Portals and CMS Portfolio
EastBanc Tachnologies
 
PPTX
Cross Platform Mobile Application Development Using Xamarin and C#
EastBanc Tachnologies
 
Unpacking .NET Core | EastBanc Technologies
EastBanc Tachnologies
 
Azure and/or AWS: How to Choose the best cloud platform for your project
EastBanc Tachnologies
 
Functional Programming with C#
EastBanc Tachnologies
 
Getting started with azure event hubs and stream analytics services
EastBanc Tachnologies
 
DevOps with Kubernetes
EastBanc Tachnologies
 
Developing Cross-Platform Web Apps with ASP.NET Core1.0
EastBanc Tachnologies
 
Highlights from MS build\\2016 Conference
EastBanc Tachnologies
 
Estimating for Fixed Price Projects
EastBanc Tachnologies
 
Async Programming with C#5: Basics and Pitfalls
EastBanc Tachnologies
 
EastBanc Technologies US-Russian Collaboration and Innovation
EastBanc Tachnologies
 
EastBanc Technologies SharePoint Portfolio
EastBanc Tachnologies
 
EastBanc Technologies Data Visualization/BI Portfolio
EastBanc Tachnologies
 
EastBanc Technologies Portals and CMS Portfolio
EastBanc Tachnologies
 
Cross Platform Mobile Application Development Using Xamarin and C#
EastBanc Tachnologies
 

Introduction to Kotlin Language and its application to Android platform

  • 1. Introduction to Kotlin language & its application to Android platform
  • 3. What is Kotlin • Kotlin is a new programming language by Jetbrains. • It runs on JVM stack. • It has ≈zero-cost Java interop. • It runs on Android, easily.
  • 4. Let’s go! • Kotlin is a new programming language by Jetbrains. • It runs on JVM stack. • It has ≈zero-cost Java interop. • It runs on Android, easily.
  • 5. Hello, world! fun main(args: Array<String>) { println("Hello, world!") }
  • 6. Hello, world! fun main(args: Array<String>) = println("Hello, world!")
  • 7. Hello, world! fun main(args: Array<String>) = args.joinToString(postfix = "!") .forEach { print(it) } > kotlin HelloKt Hello world
  • 8. Why Kotlin? • Concise — write less boilerplate. • Interoperable — write alongside your Java code. • Multi-paradigm — you can write functional-alike code. • Promising — developed by developers for developers. • It runs on Android, easily!
  • 10. Why Kotlin? • Android runs using fork of Apache Harmony (≈Java 6). • Starting from Android API 19 (Android 4.4) it supports Java 7 features. • Android N (Nutella? 6.1?) brings support for Java 8. • But it is still Java…
  • 11. Why Kotlin? • There are lot of modern features and approaches that are unavailable even in Java 8. • Typical Java code is bloated, has a lot of boilerplate. • Kotlin is much more expressive than Java.
  • 12. Why Kotlin? final Config config = playlist.getConfig(); if (config != null && config.getUrls() != null) { for (final Url url : config.getUrls()) { if (url.getFormat().equals("txt")) { this.url = url; } } }
  • 13. Why Kotlin? playlist.config?.urls ?.firstOrNull { it.format == "txt" } ?.let { this.url = it.url }
  • 15. Null safety • You won’t see NPE anymore (unless you want) • In pure Kotlin, you can have something non-null: • var foo: String = "foo" • Or nullable • var bar: String? = "bar" • Then: • foo = null → compilation error • bar = null → OK
  • 16. Null safety • var foo: String = "foo" • var bar: String? = "bar" • foo.length → 3 • bar.length → ???
  • 17. Null safety • var foo: String = "foo" • var bar: String? = "bar" • foo.length → 3 • bar.length → compilation error • Call is null-unsafe, there are two methods to fix it: • bar?.length → 3 (or null if bar == null) • bar!!.length → 3 (or NPE if bar == null)
  • 18. Null safety • var foo: String = "foo" • var bar: String? = "bar" • if (bar != null) { • // bar is effectively not null, it can be treated as String, not String? • bar.length → 3 • }
  • 19. Null safety • Kotlin understands lot of Java annotations for null-safety (JSR-308, Guava, Android, Jetbrains, etc.) • If nothing is specified, you can treat Java object as Nullable
  • 20. Null safety • Kotlin understands lot of Java annotations for null-safety (JSR-308, Guava, Android, Jetbrains, etc.) • If nothing is specified, you can treat Java object as Nullable • Or NotNull! • It’s up to you, and you should take care of proper handling nulls.
  • 21. Type inference • var bar: CharSequence? = "bar" • if (bar != null && bar is String) { • // bar can be treated as String without implicit conversion • bar.length → 3 • }
  • 22. Type inference • fun List.reversed() = Collections.reverse(list) • Return type List is inferred automatically • //effectively fun List.reversed() : List = Collections.reverse(list)
  • 23. Lambdas • Kotlin has it • And it helps a lot • Works fine for SAM
  • 24. Lambdas strings .filter( { it.count { it in "aeiou" } >= 3 } ) .filterNot { it.contains("ab|cd|pq|xy".toRegex()) } .filter { s -> s.contains("([a-z])1".toRegex()) } .size.toString()
  • 25. Lambdas • Can be in-lined. • Can use anonymous class if run on JVM 6. • Can use native Java lambdas if run on JVM 8.
  • 26. Expressivity • new Foo() → foo() • foo.bar(); → foo.bar() • Arrays.asList("foo", "bar") → listOf("foo", "bar")
  • 27. Collections operations • Lot of functional-alike operations and possibilities. • You don’t need to write loops anymore. • Loops are not prohibited. • We can have Streams on Java 6.
  • 28. Lambdas strings .filter( { it.count { it in "aeiou" } >= 3 } ) .filterNot { it.contains("ab|cd|pq|xy".toRegex()) } .filter { s -> s.contains("([a-z])1".toRegex()) } .size.toString()
  • 29. Java Beans, POJOs and so on • Write fields • Write constructors • Write getters and setters • Write equals() and hashCode() • …
  • 30. Properties • var age: Int = 0 • Can be accessed as a field from Kotlin. • Getters and setters are generated automatically for Java. • If Java code has getters and setters, it can be accessed as property from Kotlin • Can be computed and even lazy
  • 31. Data classes • data class User(var name: String, var age: Int) • Compiler generates getters and setters for Java interop • Compiler generates equals() and hashCode() • Compiler generates copy() method — flexible clone() replacement
  • 32. Data classes • data class User(val name: String, val age: Int) • 5 times less LOC. • No need to maintain methods consistency. • No need to write builders and/or numerous constructors. • Less tests to be written.
  • 33. Data classes • Model and ViewModel conversion to Kotlin • Made automatically • Was: 1750 LOC in 23 files • Now: 800 LOC • And lot of tests are now redundant!
  • 34. Extension methods • Usual Java project has 5-10 *Utils classes. • Reasons: • Some core/library classes are final • Sometimes you don’t need inheritance • Even standard routines are often wrapped with utility classes • Collections.sort(list)
  • 35. Extension methods • You can define extension method • fun List.sort() • Effectively it’ll have the same access policies as your static methods in *Utils • But it can be called directly on instance! • fun List.sort() = Collections.sort(this) • someList.sort()
  • 36. Extension methods • You can handle even null instances: fun String?.toast(context: Context) { if (this != null) Toast.makeToast(context, this, Toast.LENGTH_LONG).show() }
  • 37. String interpolation • println("Hello, world!") • println("Hello, $name!") • println("Hello, ${name.toCamelCase()}!")
  • 38. Anko • DSL for Android verticalLayout { val name = editText() button("Say Hello") { onClick { toast("Hello, ${name.text}!") } } }
  • 39. Anko • DSL for Android. • Shortcuts for widely used features (logging, intents, etc.). • SQLite bindings. • Easy (compared to core Android) async operations.
  • 40. Useful libraries • RxKotlin — FRP in Kotlin manner • Spek — Unit tests (if we still need it) • Kotlin Android extensions — built-it ButterKnife • Kotson — Gson with Kotlin flavor
  • 42. Cost of usage Each respective use has a .class method cost of • Java 6 anonymous class: 2 • Java 8 lambda: 1 • Java 8 lambda with Retrolambda: 6 • Java 8 method reference: 0 • Java 8 method reference with Retrolambda: 5 • Kotlin with Java Runnable expression: 3 • Kotlin with native function expression: 4
  • 43. Cost of usage • Kotlin stdlib contains ≈7K methods • Some part of stdlib is going to be extracted and inlined compile-time • And ProGuard strips unused methods just perfect
  • 44. Build and tools • Ant tasks, Maven and Gradle plugins • Console compiler and REPL • IntelliJ IDEA — out of the box • Android Studio, other Jetbrains IDEs — as plugin • Eclipse — plugin
  • 45. Build and tools • Can be compiled to run on JVM. • Can be run using Jack (Java Android Compiler Kit) • Can be compiled to JS. • Can be used everywhere where Java is used.
  • 46. Kotlin pros and cons • It’s short and easy. • It has zero-cost Java interoperability. • You’re not obliged to rewrite all your code in Kotlin. • You can apply modern approaches (like FRP) without bloating your code. • And you could always go back to Java (but you won’t). • Longer compile time. • Heavy resources usage. • Some overhead caused by stdlib included in dex file. • Sometimes errors are cryptic. • There are some bugs and issues in language and tools. • Community is not so huge as Java one.
  • 48. Books • Kotlin for Android Developers. • The first (and only) book about Kotlin • Regular updates with new language features • https://leanpub.com/kotlin-for-android- developers
  • 49. Books • Kotlin in Action. • A book by language authors • WIP, 8/14 chapters are ready, available for early access • https://www.manning.com/books/kotlin- in-action
  • 50. Links • https://kotlinlang.org — official site • http://blog.jetbrains.com/kotlin/ — Jetbrains blog • http://kotlinlang.slack.com/ + http://kotlinslackin.herokuapp.com/ — community Slack channel • https://www.reddit.com/r/Kotlin/ — subreddit • https://github.com/JetBrains/kotlin — it’s open, yeah! • https://kotlinlang.org/docs/tutorials/koans.html — simple tasks to get familiar with language. • http://try.kotlinlang.org — TRY IT, NOW!
  • 51. THANK YOU Oleg Godovykh Software Engineer [email protected] 202-295-3000 http://eastbanctech.com