SlideShare a Scribd company logo
Hello To Kotlin
@ArbazPirwani
Hello to Kotlin
life begins
at the end of your
COMFORT
ZONE-Neale Donald Walsch-
Hello to Kotlin
Kick Start With Kotlin
Arbaz Pirwani
@arbazpirwani
Modern Language
Hello to Kotlin
2016 2017 2018 2019 2020
Kotlin Timeline
2016 2017 2018 2019 2020
1.0
Kotlin Timeline
2016 2017 2018 2019 2020
1.0 Google I/O: Kotlin Officially supported language for Android
Kotlin Timeline
2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
Kotlin Timeline
2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
Coroutines Preferred
Kotlin Timeline
Kotlin Timeline
2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
You are here
Coroutines Preferred
WHY KOTLIN?
- Google Preferred Language
- Statistically typed
- Type Inference
- Developed by Jetbrains
- Concise
- 100% interoperable with Java
- Null Safety
- And many more.
I don’t like Kotlin
I Love Kotlin
Java vs Kotlin
Java to Kotlin
Hello to Kotlin
Multiplatform
projects
Server
Kotlin/JVM
Android
Kotlin/JVM
Browser
Kotlin/JS
iOS
Kotlin/Native
Hello to Kotlin
Question Of The Day
WHY DO KOTLIN AND JAVA PROGRAMMERS WEAR GLASSES?
BECAUSE THEY DON’T SEE SHARP.BECAUSE THEY DON’T SEE SHARP.
Tools For Kotlin.
https://www.jetbrains.com/idea/download/
Why Kotlin?
Expressiveness Safety
Interoperability Structured
concurrency
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Why Kotlin?
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Nullability in the
type system
Why Kotlin?
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Nullability in the
type system
Lambdas
Why Kotlin?
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Nullability in the
type system
Lambdas
Extension
functions
Why Kotlin?
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Nullability in the
type system
Lambdas
Template
expressions
Extension
functions
Why Kotlin?
class MainActivity : AppCompatActivity () {
override fun onCreate(savedInstanceState: Bundle?) {
...
fab.setOnClickListener { view ->
Snackbar.make(view,
"Hello ${name.capitalize()}",
Snackbar.LENGTH_LONG).show()
}
fab.backgroundTintList = backgroundTintList
}
}
Nullability in the
type system
Lambdas
Template
expressions
Extension
functions
Property access
syntax for getters
and setters
Why Kotlin?
Kotlin Uptake
60% of Pro Android Developers use Kotlin
70% of Top 1000 Apps contain Kotlin code
Source: Google internal data, May 2020
● Data Classes
● Extension Methods
● Elvis Operator
● Properties
● Default Parameters
● Type Aliases
● Named Parameters
● Spread Operator
● Auto Casts
● Covariance
● Null Safety
● Operator Overloading
● Type Inference
● DSL Support
● Type-Safe Builders
● Coroutines
● String Interpolation
● Ranges
● Map Array Syntax
● Inline Functions
● Sealed Classes
● Delegation
● Destructuring
● KDoc
Coroutine
s
Coroutines
● Coroutines are like very light-weight threads
● Asynchronous programming made easy
● No callbacks
● No complex functionality
VS
Kotlin & Swift
● The syntax of Swift doesn’t just resemble that of Kotlin: in
small chunks of code there can be up to 77% string
similarity.
● At the very least, it should be noted that while Swift
appeared in 2013, Kotlin originated back in 2011. Hence,
even though comparing Kotlin to Swift (in this exact
order) can be convenient due to Swift’s earlier
introduction to a wide audience, any ‘copycat’ attitudes
towards Kotlin aren’t justified.
Kotlin & Swift
● Available on both mobile-client and back-end server
● Highly performant and statically-typed
● Kotlin also can be used for web front-end via Kotlin.JS
Swift is like Kotlin:
Hello World
Swift
print("Hello, world!")
Kotlin
println("Hello, world!")
Swift
var myVariable = 42
myVariable = 50
let myConstant = 42
Kotlin
var myVariable = 42
myVariable = 50
val myConstant = 42
Swift is like Kotlin:
Variables And Constants
Swift
let explicitDouble: Double = 42
Kotlin
val explicitDouble: Double = 42.0
Swift is like Kotlin:
Explicit Types
Swift
var shoppingList = ["catfish", "water",
"tulips", "blue paint"]
shoppingList[1] = "bottle of water"
Kotlin
val shoppingList = arrayOf("catfish", "water",
"tulips", "blue paint")
shoppingList[1] = "bottle of water"
Swift is like Kotlin:
Arrays
Swift
func greet(_ name: String,_ day: String) -> String {
return "Hello (name), today is (day)."
}
greet("Bob", "Tuesday")
Kotlin
fun greet(name: String, day: String): String {
return "Hello $name, today is $day."
}
greet("Bob", "Tuesday")
Swift is like Kotlin:
Functions
Swift
class Shape {
var numberOfSides = 0
func simpleDescription() -> String {
return "A shape with (numberOfSides) sides."
}
}
Kotlin
class Shape {
var numberOfSides = 0
fun simpleDescription()
= "A shape with $numberOfSides sides."
}
Swift is like Kotlin:
Classes
• Advantages over Java 7 are overwhelming
• Java 8 introduced
• Lambdas
• Null safety (“Optional” class)
• Default methods
• Streams API
• New Date & Time API
Java strikes back with Java 8
• Is more elegant, concise and safe
• Has more cool stuff
But even with Java 8 Kotlin still...
Hello to Kotlin
• Functions - definition in package or in class
• Immutable/mutable variables
• No “new” keyword
• Type inference
• No checked exceptions
• No primitive types
• No static members
Basic syntax and rules
More elegant?
• Primary constructors
• No fields, just properties
• Bean style classes easy to declare
• By default, all classes are final
Basic syntax and rules cont’d
More elegant?
• Null reference – Billion dollar mistake
• Kotlin is designed in a way that aims to eliminate NPE from our code
Null Safety
More elegant?
Tony Hoare
• Declaration-site variance
• out / in generics modifiers
• Supports use-site variance also
• No wildcard syntax, out / in used
Generics
More elegant?
MORE COOL STUFF
• Default argument values can be defined
• Arguments with default values are optional
• No more need for function overloading (almost)
• Kotlin classes can have only one constructor
• Arguments can be called by name
• When passing arguments by name ordering doesn’t matter
Default arguments and
named arguments
• Simpler “is it in range” check
• Can be used for any type that implements Comparable
• “both ends“ included
• “..” operator is translated to “rangeTo” function
• “rangeTo” function is implemented as extension function on
Comparable
• Numerical ranges can be iterated over
• In both directions and in arbitrary steps
Ranges
Ranges
• Java’s instaceof not very practical
• No !instanceof
• Meet Kotlin’s "is“
• "is" negation "!is“
• Automatic type cast when “is” evaluates true inside if / when
blocks
Pattern matching
AND MANY MORE
Resources
• https://kotlinlang.org/
• https://play.kotlinlang.org/
• http://nilhcem.com/swift-is-like-kotlin/
FreeCodeCamp.org
Android Developers
Hello to Kotlin
Best Kotlin Learning Resources
Arbaz Pirwani
Hello to Kotlin

More Related Content

PPTX
Kotlin for android
PPTX
Intro to Kotlin
PDF
Software Engineering Thailand: Programming with Scala
PPTX
Introduction to Kotlin for Android developers
PDF
PPTX
Get started with android DSC HCMUT
PPTX
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
PPTX
Introduction to Koltin for Android Part I
Kotlin for android
Intro to Kotlin
Software Engineering Thailand: Programming with Scala
Introduction to Kotlin for Android developers
Get started with android DSC HCMUT
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Introduction to Koltin for Android Part I

Similar to Hello to Kotlin (20)

PDF
Swift and Kotlin Presentation
PDF
Kotlin for Android Developers - 1
PDF
Kotlin from-scratch
PPTX
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
PPTX
What's new with Kotlin - Google IO18' extended Covenant University.
PDF
Kotlin: Why Do You Care?
PDF
Kickstarting Kotlin Culture, Part 1 - Neil Power
PDF
Dear Kotliners - Java Developers are Humans too
PPTX
Introduction to Kotlin Language and its application to Android platform
PDF
Basics of kotlin ASJ
PPTX
Introduction to Kotlin
PDF
A quick and fast intro to Kotlin
PDF
Kotlin fundamentals - By: Ipan Ardian
PDF
Kotlin Fundamentals
PPTX
Kotlin for android 2019
PDF
Android 101 - Kotlin ( Future of Android Development)
PDF
Koin Quickstart
PPTX
Kotlin
PDF
Summer of Tech 2017 - Kotlin/Android bootcamp
PDF
Having Fun with Kotlin Android - DILo Surabaya
Swift and Kotlin Presentation
Kotlin for Android Developers - 1
Kotlin from-scratch
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
What's new with Kotlin - Google IO18' extended Covenant University.
Kotlin: Why Do You Care?
Kickstarting Kotlin Culture, Part 1 - Neil Power
Dear Kotliners - Java Developers are Humans too
Introduction to Kotlin Language and its application to Android platform
Basics of kotlin ASJ
Introduction to Kotlin
A quick and fast intro to Kotlin
Kotlin fundamentals - By: Ipan Ardian
Kotlin Fundamentals
Kotlin for android 2019
Android 101 - Kotlin ( Future of Android Development)
Koin Quickstart
Kotlin
Summer of Tech 2017 - Kotlin/Android bootcamp
Having Fun with Kotlin Android - DILo Surabaya
Ad

More from FatimaYousif11 (15)

PPTX
Day 2 react bootcamp
PPTX
The concept of vector art
PPTX
CV/resume writing
PPTX
Day 8 sketchware
PPT
Firebase
PDF
Android local databases
PPTX
Day 5 android app code advancement
PPTX
Day 4 android bootcamp
PPTX
Android app code mediator
PPTX
Android App code starter
PPTX
Android bootcamp-day1
PPTX
Getting started with android development
PPTX
Hacktoberfest slides
PPTX
Info session about dsc
Day 2 react bootcamp
The concept of vector art
CV/resume writing
Day 8 sketchware
Firebase
Android local databases
Day 5 android app code advancement
Day 4 android bootcamp
Android app code mediator
Android App code starter
Android bootcamp-day1
Getting started with android development
Hacktoberfest slides
Info session about dsc
Ad

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx

Hello to Kotlin

  • 3. life begins at the end of your COMFORT ZONE-Neale Donald Walsch-
  • 5. Kick Start With Kotlin Arbaz Pirwani @arbazpirwani
  • 8. 2016 2017 2018 2019 2020 Kotlin Timeline
  • 9. 2016 2017 2018 2019 2020 1.0 Kotlin Timeline
  • 10. 2016 2017 2018 2019 2020 1.0 Google I/O: Kotlin Officially supported language for Android Kotlin Timeline
  • 11. 2016 2017 2018 2019 2020 1.0 Google I/O: Kotlin Officially supported language for Android Google I/O: Android goes Kotlin-first Kotlin Timeline
  • 12. 2016 2017 2018 2019 2020 1.0 Google I/O: Kotlin Officially supported language for Android Google I/O: Android goes Kotlin-first Coroutines Preferred Kotlin Timeline
  • 13. Kotlin Timeline 2016 2017 2018 2019 2020 1.0 Google I/O: Kotlin Officially supported language for Android Google I/O: Android goes Kotlin-first You are here Coroutines Preferred
  • 15. - Google Preferred Language - Statistically typed - Type Inference - Developed by Jetbrains - Concise - 100% interoperable with Java - Null Safety - And many more.
  • 16. I don’t like Kotlin
  • 23. Question Of The Day WHY DO KOTLIN AND JAVA PROGRAMMERS WEAR GLASSES? BECAUSE THEY DON’T SEE SHARP.BECAUSE THEY DON’T SEE SHARP.
  • 27. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Why Kotlin?
  • 28. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Nullability in the type system Why Kotlin?
  • 29. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Nullability in the type system Lambdas Why Kotlin?
  • 30. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Nullability in the type system Lambdas Extension functions Why Kotlin?
  • 31. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Nullability in the type system Lambdas Template expressions Extension functions Why Kotlin?
  • 32. class MainActivity : AppCompatActivity () { override fun onCreate(savedInstanceState: Bundle?) { ... fab.setOnClickListener { view -> Snackbar.make(view, "Hello ${name.capitalize()}", Snackbar.LENGTH_LONG).show() } fab.backgroundTintList = backgroundTintList } } Nullability in the type system Lambdas Template expressions Extension functions Property access syntax for getters and setters Why Kotlin?
  • 33. Kotlin Uptake 60% of Pro Android Developers use Kotlin 70% of Top 1000 Apps contain Kotlin code Source: Google internal data, May 2020
  • 34. ● Data Classes ● Extension Methods ● Elvis Operator ● Properties ● Default Parameters ● Type Aliases ● Named Parameters ● Spread Operator ● Auto Casts ● Covariance ● Null Safety ● Operator Overloading ● Type Inference ● DSL Support ● Type-Safe Builders ● Coroutines ● String Interpolation ● Ranges ● Map Array Syntax ● Inline Functions ● Sealed Classes ● Delegation ● Destructuring ● KDoc Coroutine s
  • 35. Coroutines ● Coroutines are like very light-weight threads ● Asynchronous programming made easy ● No callbacks ● No complex functionality
  • 36. VS
  • 37. Kotlin & Swift ● The syntax of Swift doesn’t just resemble that of Kotlin: in small chunks of code there can be up to 77% string similarity. ● At the very least, it should be noted that while Swift appeared in 2013, Kotlin originated back in 2011. Hence, even though comparing Kotlin to Swift (in this exact order) can be convenient due to Swift’s earlier introduction to a wide audience, any ‘copycat’ attitudes towards Kotlin aren’t justified.
  • 38. Kotlin & Swift ● Available on both mobile-client and back-end server ● Highly performant and statically-typed ● Kotlin also can be used for web front-end via Kotlin.JS
  • 39. Swift is like Kotlin: Hello World Swift print("Hello, world!") Kotlin println("Hello, world!")
  • 40. Swift var myVariable = 42 myVariable = 50 let myConstant = 42 Kotlin var myVariable = 42 myVariable = 50 val myConstant = 42 Swift is like Kotlin: Variables And Constants
  • 41. Swift let explicitDouble: Double = 42 Kotlin val explicitDouble: Double = 42.0 Swift is like Kotlin: Explicit Types
  • 42. Swift var shoppingList = ["catfish", "water", "tulips", "blue paint"] shoppingList[1] = "bottle of water" Kotlin val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint") shoppingList[1] = "bottle of water" Swift is like Kotlin: Arrays
  • 43. Swift func greet(_ name: String,_ day: String) -> String { return "Hello (name), today is (day)." } greet("Bob", "Tuesday") Kotlin fun greet(name: String, day: String): String { return "Hello $name, today is $day." } greet("Bob", "Tuesday") Swift is like Kotlin: Functions
  • 44. Swift class Shape { var numberOfSides = 0 func simpleDescription() -> String { return "A shape with (numberOfSides) sides." } } Kotlin class Shape { var numberOfSides = 0 fun simpleDescription() = "A shape with $numberOfSides sides." } Swift is like Kotlin: Classes
  • 45. • Advantages over Java 7 are overwhelming • Java 8 introduced • Lambdas • Null safety (“Optional” class) • Default methods • Streams API • New Date & Time API Java strikes back with Java 8
  • 46. • Is more elegant, concise and safe • Has more cool stuff But even with Java 8 Kotlin still...
  • 48. • Functions - definition in package or in class • Immutable/mutable variables • No “new” keyword • Type inference • No checked exceptions • No primitive types • No static members Basic syntax and rules More elegant?
  • 49. • Primary constructors • No fields, just properties • Bean style classes easy to declare • By default, all classes are final Basic syntax and rules cont’d More elegant?
  • 50. • Null reference – Billion dollar mistake • Kotlin is designed in a way that aims to eliminate NPE from our code Null Safety More elegant? Tony Hoare
  • 51. • Declaration-site variance • out / in generics modifiers • Supports use-site variance also • No wildcard syntax, out / in used Generics More elegant?
  • 53. • Default argument values can be defined • Arguments with default values are optional • No more need for function overloading (almost) • Kotlin classes can have only one constructor • Arguments can be called by name • When passing arguments by name ordering doesn’t matter Default arguments and named arguments
  • 54. • Simpler “is it in range” check • Can be used for any type that implements Comparable • “both ends“ included • “..” operator is translated to “rangeTo” function • “rangeTo” function is implemented as extension function on Comparable • Numerical ranges can be iterated over • In both directions and in arbitrary steps Ranges
  • 56. • Java’s instaceof not very practical • No !instanceof • Meet Kotlin’s "is“ • "is" negation "!is“ • Automatic type cast when “is” evaluates true inside if / when blocks Pattern matching
  • 62. Best Kotlin Learning Resources