SlideShare a Scribd company logo
1 of 29
Download to read offline
Developing
Android apps
with Kotlin
AVGeeks, June 2016
Shem Magnezi
Shem Magnezi
@shemag8 | shem8.github.com
Java is great
▣ Very popular.
▣ Great community.
▣ Lots of frameworks and libraries.
▣ Supported by big companies (Oracle &
Google).
▣ Portable, fast, well documented.
▣ Great IDEs
▣ You can write server side, web and mobile.
Yes but...
▣ Lot’s of boilerplate
▣ Null checks
▣ Exception handling
▣ Function pointers
▣ Data classes (POJO)
▣ Extension functions
▣ Operator overloading
▣ String interpolation
▣ And more...
On Android it even worse
▣ Barely support Java 8 (N+)
▣ Partially support Java 7 (KitKat+)
▣ There are some libraries that fill some of the
missing features (retro lambda, RX, etc..) but
it’s not the same.
▣ It mainly feel too ‘heavy’ for front end code.
Kotlin
Statically typed programming language
for the JVM, Android and the browser
100% interoperable with Java™
Kotlin?
▣ Open source, lead by JetBrains.
▣ JVM language (Like Scala, Groovy and Clojure)
▣ Can call Java code and vice versa.
▣ Fully integrated IDE.
▣ Small (600KB before ProGuard).
▣ Statically typed so no runtime overhead.
▣ Used by a lot of big companies, even by the
Android team (data binding).
Code!
1.
Basic syntax
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")
}
fun mul(x: Int, y: Int = 2): Int {
return x * y
}
fun mul(x: Int, y: Int = 2) = x * y
view.setOnClickListener({ //click handling })
if (obj is String) {
print(obj.length)
}
val items = listOf(1, 2, 3, 4)
items.first() == 1
items.last() == 4
items.filter { it % 2 == 0 } // returns [2, 4]
ints.forEach {
if (it == 0) return
print(it)
}
2.
Null Safety
‘’
I call it my billion-dollar mistake. It
was the invention of the null
reference in 1965 ... My goal was to
ensure that all use of references
should be absolutely safe... This has
led to innumerable errors,
vulnerabilities, and system crashes,
which have probably caused a
billion dollars of pain and damage in
the last forty years.
Tony Hoare
var a: String = "abc"
a = null // compilation error
var b: String? = "abc"
b = null // ok
val l = b?.length ?: -1
3.
Data Classes
data class User(val name: String, val age: Int)
You get for free:
▣ equals()
▣ hashCode()
▣ toString() of the form "User(name=John, age=42)",
▣ copy() function
▣ getters()
4.
Extensions
Functions
fun Date.isThuesday() Boolean {
return day == 2
}
if (date.isTuesday) {
...
}
fun Date.isThuesday() = day == 2
fun SQLiteDatabase.inTransaction(func: () -> Unit) {
beginTransaction()
try {
func()
setTransactionSuccessful()
} finally {
endTransaction()
}
}
db.inTransaction {
}
fun AppCompatActivity.navigate(frag: Fragment) {
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(content.id, frag);
fragmentTransaction.commit();
}
fun Fragment.userError(msg: String?) {
Snackbar.make(view, msg, Snackbar.LENGTH_LONG).show()
}
fun SharedPreferences.edit(func:SharedPreferences.Editor.(): Unit) {
val editor = edit()
editor.func()
editor.apply()
}
fun SharedPreferences.Editor.set(pair: Pair<String, String>) = putString(pair.first, pair.second)
preferences.edit {
set("foo" to "bar")
set("fizz" to "buzz")
remove("username")
}
inline fun <T: View> T.afterMeasured(crossinline f: T.() -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (measuredWidth > 0 && measuredHeight > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
}
})
}
recycler.afterMeasured {
val columnCount = width / columnWidth
layoutManager = GridLayoutManager(context, columnCount)
}
5.
Android
Extensions
// Using R.layout.activity_main from the main source set
import kotlinx.android.synthetic.main.activity_main.*
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.setText("Hello, world!") // Instead of findView(R.id.textView) as TextView
}
}
6.
Anko library
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
verticalLayout {
padding = dip(30)
editText {
hint = "Name"
textSize = 24f
}
editText {
hint = "Password"
textSize = 24f
}
button("Login") {
textSize = 26f
}
}
}
There is much more:
▣ kotlinlang.org
▣ blog.jetbrains.com/kotlin
▣ kotlinlang.org/docs/resources.html
▣ Kara- An MVC Framework
▣ Android Kotlin Extensions- A collection of Android Kotlin
extensions
▣ KAndroid- Kotlin library for Android
▣ Anko- Pleasant Android application development
Thanks!
Any questions?
You can find this presentation at: shem8.github.io
smagnezi8@gmail.com
Presentation template by SlidesCarnival | Photographs by Unsplash
Credits
Android Development with Kotlin - Jake Wharton
Droidcon SF - Better Android Development with Kotlin and
Gradle
Special thanks to all the people who made and released these
awesome resources for free:
▣ Presentation template by SlidesCarnival
▣ Photographs by Unsplash

More Related Content

What's hot

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseHeiko Behrens
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7Dongho Cho
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than WebHeiko Behrens
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose worldFabio Collini
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩GDG Korea
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and AndroidHeiko Behrens
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)Simon Su
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programmingAnand Dhana
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile servicesAymeric Weinbach
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)Giuseppe Filograno
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQueryPhDBrown
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confFabio Collini
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmFabio Collini
 

What's hot (20)

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and Android
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
Green dao
Green daoGreen dao
Green dao
 
Green dao
Green daoGreen dao
Green dao
 

Similar to Building android apps with kotlin

What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016DesertJames
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageDroidConTLV
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Peter Higgins
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
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
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java DevelopersChristoph Pickl
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKirill Rozov
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 

Similar to Building android apps with kotlin (20)

What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Java
JavaJava
Java
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritage
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
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
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
mobl
moblmobl
mobl
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platforms
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
jQuery
jQueryjQuery
jQuery
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 

More from Shem Magnezi

The Future of Work(ers)
The Future of Work(ers)The Future of Work(ers)
The Future of Work(ers)Shem Magnezi
 
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...Shem Magnezi
 
Good rules for bad apps
Good rules for bad appsGood rules for bad apps
Good rules for bad appsShem Magnezi
 
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...Shem Magnezi
 
Iterating on your idea
Iterating on your ideaIterating on your idea
Iterating on your ideaShem Magnezi
 
The Redux State of the Art
The Redux State of the ArtThe Redux State of the Art
The Redux State of the ArtShem Magnezi
 
Startup hackers toolbox
Startup hackers toolboxStartup hackers toolbox
Startup hackers toolboxShem Magnezi
 
Fuck you startup world
Fuck you startup worldFuck you startup world
Fuck you startup worldShem Magnezi
 
The Future of Work
The Future of WorkThe Future of Work
The Future of WorkShem Magnezi
 
Good rules for bad apps
Good rules for bad appsGood rules for bad apps
Good rules for bad appsShem Magnezi
 
Andriod dev toolbox part 2
Andriod dev toolbox  part 2Andriod dev toolbox  part 2
Andriod dev toolbox part 2Shem Magnezi
 
Know what (not) to build
Know what (not) to buildKnow what (not) to build
Know what (not) to buildShem Magnezi
 
Android ui tips & tricks
Android ui tips & tricksAndroid ui tips & tricks
Android ui tips & tricksShem Magnezi
 

More from Shem Magnezi (13)

The Future of Work(ers)
The Future of Work(ers)The Future of Work(ers)
The Future of Work(ers)
 
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
 
Good rules for bad apps
Good rules for bad appsGood rules for bad apps
Good rules for bad apps
 
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
 
Iterating on your idea
Iterating on your ideaIterating on your idea
Iterating on your idea
 
The Redux State of the Art
The Redux State of the ArtThe Redux State of the Art
The Redux State of the Art
 
Startup hackers toolbox
Startup hackers toolboxStartup hackers toolbox
Startup hackers toolbox
 
Fuck you startup world
Fuck you startup worldFuck you startup world
Fuck you startup world
 
The Future of Work
The Future of WorkThe Future of Work
The Future of Work
 
Good rules for bad apps
Good rules for bad appsGood rules for bad apps
Good rules for bad apps
 
Andriod dev toolbox part 2
Andriod dev toolbox  part 2Andriod dev toolbox  part 2
Andriod dev toolbox part 2
 
Know what (not) to build
Know what (not) to buildKnow what (not) to build
Know what (not) to build
 
Android ui tips & tricks
Android ui tips & tricksAndroid ui tips & tricks
Android ui tips & tricks
 

Recently uploaded

SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...Bert Jan Schrijver
 
Preparing BitVisor for Supporting Multiple Architectures
Preparing BitVisor for Supporting Multiple ArchitecturesPreparing BitVisor for Supporting Multiple Architectures
Preparing BitVisor for Supporting Multiple ArchitecturesAke Koomsin
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...kalichargn70th171
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...OnePlan Solutions
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...Milind Agarwal
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dbaRemote DBA Services
 
Reliable from-source builds (Qshare 28 Nov 2023).pdf
Reliable from-source builds (Qshare 28 Nov 2023).pdfReliable from-source builds (Qshare 28 Nov 2023).pdf
Reliable from-source builds (Qshare 28 Nov 2023).pdfRalf Gommers
 
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Piyovi
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flinkconfluent
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapIshara Amarasekera
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
What are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxWhat are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxkzayra69
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
The State of the Green IT at the beginning of 2024
The State of the Green IT at the beginning of 2024The State of the Green IT at the beginning of 2024
The State of the Green IT at the beginning of 2024Artur Skowroński
 
logical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxlogical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxRemote DBA Services
 
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptx
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptxSPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptx
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptxVersion 1 Analytics
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata
 

Recently uploaded (20)

SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
 
Preparing BitVisor for Supporting Multiple Architectures
Preparing BitVisor for Supporting Multiple ArchitecturesPreparing BitVisor for Supporting Multiple Architectures
Preparing BitVisor for Supporting Multiple Architectures
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...
Leveraging the Expertise of a Social Media Fraud Analyst to Safeguard Brand R...
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dba
 
Reliable from-source builds (Qshare 28 Nov 2023).pdf
Reliable from-source builds (Qshare 28 Nov 2023).pdfReliable from-source builds (Qshare 28 Nov 2023).pdf
Reliable from-source builds (Qshare 28 Nov 2023).pdf
 
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flink
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery Roadmap
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
What are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxWhat are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docx
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
The State of the Green IT at the beginning of 2024
The State of the Green IT at the beginning of 2024The State of the Green IT at the beginning of 2024
The State of the Green IT at the beginning of 2024
 
logical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxlogical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptx
 
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptx
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptxSPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptx
SPSS Statistics - Encrypting a Syntax File in IBM SPSS Statistics.pptx
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024
 

Building android apps with kotlin

  • 2. Shem Magnezi @shemag8 | shem8.github.com
  • 3. Java is great ▣ Very popular. ▣ Great community. ▣ Lots of frameworks and libraries. ▣ Supported by big companies (Oracle & Google). ▣ Portable, fast, well documented. ▣ Great IDEs ▣ You can write server side, web and mobile.
  • 4. Yes but... ▣ Lot’s of boilerplate ▣ Null checks ▣ Exception handling ▣ Function pointers ▣ Data classes (POJO) ▣ Extension functions ▣ Operator overloading ▣ String interpolation ▣ And more...
  • 5. On Android it even worse ▣ Barely support Java 8 (N+) ▣ Partially support Java 7 (KitKat+) ▣ There are some libraries that fill some of the missing features (retro lambda, RX, etc..) but it’s not the same. ▣ It mainly feel too ‘heavy’ for front end code.
  • 6. Kotlin Statically typed programming language for the JVM, Android and the browser 100% interoperable with Java™
  • 7. Kotlin? ▣ Open source, lead by JetBrains. ▣ JVM language (Like Scala, Groovy and Clojure) ▣ Can call Java code and vice versa. ▣ Fully integrated IDE. ▣ Small (600KB before ProGuard). ▣ Statically typed so no runtime overhead. ▣ Used by a lot of big companies, even by the Android team (data binding).
  • 10. 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") } fun mul(x: Int, y: Int = 2): Int { return x * y } fun mul(x: Int, y: Int = 2) = x * y view.setOnClickListener({ //click handling })
  • 11. if (obj is String) { print(obj.length) } val items = listOf(1, 2, 3, 4) items.first() == 1 items.last() == 4 items.filter { it % 2 == 0 } // returns [2, 4] ints.forEach { if (it == 0) return print(it) }
  • 13. ‘’ I call it my billion-dollar mistake. It was the invention of the null reference in 1965 ... My goal was to ensure that all use of references should be absolutely safe... This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. Tony Hoare
  • 14. var a: String = "abc" a = null // compilation error var b: String? = "abc" b = null // ok val l = b?.length ?: -1
  • 16. data class User(val name: String, val age: Int) You get for free: ▣ equals() ▣ hashCode() ▣ toString() of the form "User(name=John, age=42)", ▣ copy() function ▣ getters()
  • 18. fun Date.isThuesday() Boolean { return day == 2 } if (date.isTuesday) { ... } fun Date.isThuesday() = day == 2
  • 19. fun SQLiteDatabase.inTransaction(func: () -> Unit) { beginTransaction() try { func() setTransactionSuccessful() } finally { endTransaction() } } db.inTransaction { }
  • 20. fun AppCompatActivity.navigate(frag: Fragment) { val fragmentTransaction = supportFragmentManager.beginTransaction() fragmentTransaction.replace(content.id, frag); fragmentTransaction.commit(); } fun Fragment.userError(msg: String?) { Snackbar.make(view, msg, Snackbar.LENGTH_LONG).show() }
  • 21. fun SharedPreferences.edit(func:SharedPreferences.Editor.(): Unit) { val editor = edit() editor.func() editor.apply() } fun SharedPreferences.Editor.set(pair: Pair<String, String>) = putString(pair.first, pair.second) preferences.edit { set("foo" to "bar") set("fizz" to "buzz") remove("username") }
  • 22. inline fun <T: View> T.afterMeasured(crossinline f: T.() -> Unit) { viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { if (measuredWidth > 0 && measuredHeight > 0) { viewTreeObserver.removeOnGlobalLayoutListener(this) f() } } }) } recycler.afterMeasured { val columnCount = width / columnWidth layoutManager = GridLayoutManager(context, columnCount) }
  • 24. // Using R.layout.activity_main from the main source set import kotlinx.android.synthetic.main.activity_main.* public class MyActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.setText("Hello, world!") // Instead of findView(R.id.textView) as TextView } }
  • 26. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) verticalLayout { padding = dip(30) editText { hint = "Name" textSize = 24f } editText { hint = "Password" textSize = 24f } button("Login") { textSize = 26f } } }
  • 27. There is much more: ▣ kotlinlang.org ▣ blog.jetbrains.com/kotlin ▣ kotlinlang.org/docs/resources.html ▣ Kara- An MVC Framework ▣ Android Kotlin Extensions- A collection of Android Kotlin extensions ▣ KAndroid- Kotlin library for Android ▣ Anko- Pleasant Android application development
  • 28. Thanks! Any questions? You can find this presentation at: shem8.github.io smagnezi8@gmail.com Presentation template by SlidesCarnival | Photographs by Unsplash
  • 29. Credits Android Development with Kotlin - Jake Wharton Droidcon SF - Better Android Development with Kotlin and Gradle Special thanks to all the people who made and released these awesome resources for free: ▣ Presentation template by SlidesCarnival ▣ Photographs by Unsplash