SlideShare a Scribd company logo
K O T L I N
ANDROID
Kotlin for Android dev
100 % interoperable
with Java
Kotlin for Android devs
Developed by JetBrains
KOTLIN
KOTLIN
2010 - Work Started
2011 - Announced
2016 - 1.0 release
2017 - 1.1 release
Official Android First Class Language
Agenda
What is Kotlin ?
Kotlin for Android devs
Why Kotlin ?
Syntax crash course
Features of Kotlin
QnA
Hands-on Session
https://www.tiobe.com/tiobe-index/
Kotlin is climbing up the ladder
• Null references are controlled by the type
system.
• No raw types
• Arrays in Kotlin are invariant
• Kotlin has proper function types, as
opposed to Java’s SAM-conversions
• Use-site variance without wildcards
• Kotlin does not have checked exceptions
Kotlin fixes a series of
issues that Java suffers
from
Checked exceptions
Primitive types that are not classes
Static members
Non-private fields
Wildcard-types
What Java has that Kotlin
does not
KOTLIN & ANDROID
Kotlin can be updated
independently from the OS.
OOP language
with functional
aspects
Modern and
powerful
language
Focuses on
safe concise
and readable
code
Its a statically-typed programming language
What is Kotlin ?
First class tool support
Statically typed programming
language for the JVM,
Android and the browser
What is Kotlin ?
Its a statically-typed programming language
Statically type
What we get by using Java 6/7 + Android -
• Inability to add methods in platform APIs ,
have to use Utils
• NO Lambdas , NO Streams
• NPE - so many of them
What we need
We need modern and smart coding language
Why Kotlin ?
• Not Functional language
• Combines OOP and Functional Programming
features
• Open source
• Targets JVM , Android and even JS
Why Kotlin ?
Kotlin has lots of advantages for #AndroiDev. By using
#Kotlin, my code is simply better for it. - Annyce Davis
I love #Kotlin. It's a breath of fresh air in the #AndroidDev world
- Donn Felker
At work we're just 100% on the #Kotlin train and yes, that
includes #AndroidDev production code! - Huyen Tue Dao
I enjoy writing in #Kotlin because I don't have to use a lot of
#AndroidDev 3rd party libraries - Dmytro Danylyk
#Kotlin enables more concise and understandable code without sacrificing performance
or safety - Dan Lew
Why Kotlin ?
Variables and properties
Syntax
val name: String ="John" //Immutable , its final
var name: String ="John" //Mutable
ex: name= "Johnny"
val name ="John" // Types are auto-inferred
val num: int =10 //Immediate assignment
var personList:List<String> = ArrayList() //Explicit type declaration
Syntax
Immutable
“Anything which will not change is val”
Mutable
“If value will be changed with time use var”
Rule of thumb
Modifiers - Class level
For members declared inside a class :
• Private - member is visible inside the class only.
• Protected - member has the same rules as private but is also available in
subclasses.
• Internal - any member inside the same module can see internal members
• Public - any member who can see the class can see it’s public members.
Default visibility is public
Modifiers - Top level
For declarations declared inside at the top level:
• Private - declaration only visible in the same file.
• Protected - not available as the top level is independent of any class
hierarchy.
• Internal - declaration visible only in the same module
• Public - declaration is visible everywhere
Default visibility is public
// Simple usage
val myValue = a
if (a < b) myValue = b
// As expression
val myValue = if ( a < b) a else b
// when replaces switch operator
when (x) {
1 -> print("First output")
2 -> print("Second output")
else -> {
print(" Nor 1 or 2 ") // This block :)
}
// for loop iterates with iterator
val list = listOf("Game of thrones","Breaking Bad","Gotham")
//while and do ..usual
while (x > 0) {
x--
}
do {
val y= someData()
} while( y!=100)
// Functions in Kotlin are declared using the fun keyword
fun sum (a: Int , b: Int) : Int {
return a + b
}
//or ..single line return
fun sum(a: Int , b: Int , c: Int) = a + b + c
//default values with functions
fun sum(a: Int , b: Int , c: Int , d: Int = 1) = a + b + c + d
Class - big picture
class Person(pName: String) {
var name: String = ""
var age: Int = -1
init {
this.name = pName
}
constructor(pName: String , pAge: Int) : this(pName) {
this.age = pAge
}
fun greet(): String {
return "Hello $name"
}
Class - big picture
class Person(pName: String) {
var name: String = ""
var age: Int = -1
init {
this.name = pName
}
constructor(pName: String , pAge: Int) : this(pName) {
this.age = pAge
}
fun greet(): String {
return "Hello $name"
}
// Instance , we call the constructor as if it were a
//regular function
val person = Person()
val me = Person("Adit")
// Kotlin - has no new keyword
Code
// The full syntax for declaring a property is
private var age:Int =0
get() = field
set(value) {
if(value>0)
field = value
}
internal fun sum(first: Int , second: Int): Int {
return first + second
}
Access modifier Keyword Name
Param name
Param type
Return type
Code
// Full syntax
internal fun sum(first: Int , second: Int): Int {
return first + second
}
// Omit access modifier
fun sum(first: Int , second: Int): Int {
return first + second
}
// Inline return
fun sum(first: Int , second: Int): Int = first + second
// Omit return type
fun sum(first: Int , second: Int) = first + second
// As a type
val sum - { first : Int, second: Int -> first + second }
Higher order functions
• Functions which return a function or take a function
as a parameter
• Used via Lambdas
• Java 6 support
NULL SAFETY
No more
Kotlin’s type system is aimed to eliminate this
forever.
Null Safety
var a: String = "abc"
a = null // compilation error
var b: String? = "abc"
b = null // ok
// what about this ?
val l = a.length // Promise no NPE crash
val l = b.length // error: b can be null
Null Safety
// You could explicitly check if b is null , and handle the options separately
val l = if (b!= null) b.length else -1
// Or ...
val length = b?.length
// Even better
val listWithNulls: List<String?> = listOf("A",null)
for (item in listWithNulls) {
item?.let { println(it)
} // prints A ignores null
Nullability
• In Java, the NullPointerException is one of the biggest headache’s
• Kotlin , ‘null’ is part of the type system
• We can explicitly declare a property , with nullable value
• For each function, we can declare whether it returns a nullable
value
• Goodbye, NullPointerException
Data classes
public class Movie {
private String name;
private String posterImgUrl;
private float rating;
public Movie(String name, String
imageUrl, float rating)
{
this.name = name;
this.posterImgUrl = imageUrl;
this.rating = rating;
}
// Getters and setters
// equals and hashCode
// toString()
}
Data classes
// Just use the keyword 'data' and see the magic
data class Movie(val name: String , val imgUrl:
String , val rating: Float)
val inception = Movie("Inception","http://
inception.com/poster.jpg",4.2)
print(inception.name)
print(inception.imgUrl)
print(inception.rating)
// Pretty print
print(inception.toString())
// Copy object
val inceptionTwo = inception.copy(imgUrl= "http://
imageUrl.com/inception2.png")
Fun tricks
fun evaluateObject(obj: Any): String {
return when(obj){
is String -> "String it is , ahoy !!"
is Int -> "Give me the 8 ball"
else -> "Object is in space"
}
}
fun ImageView.loadUrl(url: String) {
Glide.with(context).load(url).into(this)
}
Extensions
public static boolean isTuesday(Date date) {
return date.getDay() == 2;
}
boolean tuesdayBool =
DateUtils.isTuesday(date);
fun Date.isTuesday(): Boolean {
return getDay() ==2
}
val dateToCheck = Date()
println(date.isTuesday())
Lambdas
myButton.setOnClickListener { navigateToDetail() }
fun apply(one: Int , two: Int , func: (Int, Int) -> Int): Int{
return func(one,two)
}
println(apply(1, 2, { a, b -> a * b }))
println(apply(1, 2, { a, b -> a * 2 - 3 * b }))
Higher order Functions
if (obj instanceOf MyType) {
((MyType)obj).getXValue();
} else {
// Oh no do more
}
Smart Casting
if (obj is MyType) {
obj.getXValue()
} else {
// Oh no do more
}
… and More
• Visibility Modifiers
• Companion Objects
• Nested, Sealed Classes
• Generics
• Coroutines
• Operator overloading
• Exceptions
• Annotations
• Reflection
• and more
… and Even More
• Infix extension methods
• Interfaces
• Interface Delegation
• Property Delegation
• Destructuring
• Safe Singletons
• Init blocks
• Enums
• Multiline Strings
• Tail recursion
CODE
❤ Kotlin
Try Kotlin online
https://goo.gl/z9Hhq6
https://fabiomsr.github.io/from-java-to-kotlin/
QnA
THANK YOU
@aditlal

More Related Content

What's hot

The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
Dariusz Lorenc
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
Ciro Rizzo
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
nklmish
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
intelliyole
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Andrey Breslav
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language design
Andrey Breslav
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
Haim Yadid
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
Codemotion
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
NAVER Engineering
 
Kotlin
KotlinKotlin
Kotlin
Rory Preddy
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 

What's hot (20)

The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language design
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin
KotlinKotlin
Kotlin
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
 

Similar to Kotlin for Android devs

Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
XPeppers
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
adityakale2110
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
Mohamed Wael
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
Abhijeet Dubey
 
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
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
Matthew Clarke
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
Oswald Campesato
 
Kotlin Basic & Android Programming
Kotlin Basic & Android ProgrammingKotlin Basic & Android Programming
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Сбертех | SberTech
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
Squareboat
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
Kurt Renzo Acosta
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
Garth Gilmour
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
Cody Engel
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
Magda Miu
 
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
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 

Similar to Kotlin for Android devs (20)

Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigerians
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
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...
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Kotlin Basic & Android Programming
Kotlin Basic & Android ProgrammingKotlin Basic & Android Programming
Kotlin Basic & Android Programming
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 

Recently uploaded

OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 

Recently uploaded (20)

OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 

Kotlin for Android devs

  • 1. K O T L I N ANDROID Kotlin for Android dev
  • 2. 100 % interoperable with Java Kotlin for Android devs Developed by JetBrains KOTLIN
  • 3. KOTLIN 2010 - Work Started 2011 - Announced 2016 - 1.0 release 2017 - 1.1 release Official Android First Class Language
  • 4. Agenda What is Kotlin ? Kotlin for Android devs Why Kotlin ? Syntax crash course Features of Kotlin QnA Hands-on Session
  • 6.
  • 7. • Null references are controlled by the type system. • No raw types • Arrays in Kotlin are invariant • Kotlin has proper function types, as opposed to Java’s SAM-conversions • Use-site variance without wildcards • Kotlin does not have checked exceptions Kotlin fixes a series of issues that Java suffers from
  • 8. Checked exceptions Primitive types that are not classes Static members Non-private fields Wildcard-types What Java has that Kotlin does not
  • 9. KOTLIN & ANDROID Kotlin can be updated independently from the OS.
  • 10. OOP language with functional aspects Modern and powerful language Focuses on safe concise and readable code Its a statically-typed programming language What is Kotlin ? First class tool support
  • 11. Statically typed programming language for the JVM, Android and the browser What is Kotlin ? Its a statically-typed programming language
  • 13. What we get by using Java 6/7 + Android - • Inability to add methods in platform APIs , have to use Utils • NO Lambdas , NO Streams • NPE - so many of them What we need We need modern and smart coding language Why Kotlin ?
  • 14. • Not Functional language • Combines OOP and Functional Programming features • Open source • Targets JVM , Android and even JS Why Kotlin ?
  • 15.
  • 16.
  • 17. Kotlin has lots of advantages for #AndroiDev. By using #Kotlin, my code is simply better for it. - Annyce Davis I love #Kotlin. It's a breath of fresh air in the #AndroidDev world - Donn Felker At work we're just 100% on the #Kotlin train and yes, that includes #AndroidDev production code! - Huyen Tue Dao I enjoy writing in #Kotlin because I don't have to use a lot of #AndroidDev 3rd party libraries - Dmytro Danylyk #Kotlin enables more concise and understandable code without sacrificing performance or safety - Dan Lew
  • 19. Variables and properties Syntax val name: String ="John" //Immutable , its final var name: String ="John" //Mutable ex: name= "Johnny" val name ="John" // Types are auto-inferred val num: int =10 //Immediate assignment var personList:List<String> = ArrayList() //Explicit type declaration
  • 20. Syntax Immutable “Anything which will not change is val” Mutable “If value will be changed with time use var” Rule of thumb
  • 21. Modifiers - Class level For members declared inside a class : • Private - member is visible inside the class only. • Protected - member has the same rules as private but is also available in subclasses. • Internal - any member inside the same module can see internal members • Public - any member who can see the class can see it’s public members. Default visibility is public
  • 22. Modifiers - Top level For declarations declared inside at the top level: • Private - declaration only visible in the same file. • Protected - not available as the top level is independent of any class hierarchy. • Internal - declaration visible only in the same module • Public - declaration is visible everywhere Default visibility is public
  • 23. // Simple usage val myValue = a if (a < b) myValue = b // As expression val myValue = if ( a < b) a else b
  • 24. // when replaces switch operator when (x) { 1 -> print("First output") 2 -> print("Second output") else -> { print(" Nor 1 or 2 ") // This block :) }
  • 25. // for loop iterates with iterator val list = listOf("Game of thrones","Breaking Bad","Gotham") //while and do ..usual while (x > 0) { x-- } do { val y= someData() } while( y!=100)
  • 26. // Functions in Kotlin are declared using the fun keyword fun sum (a: Int , b: Int) : Int { return a + b } //or ..single line return fun sum(a: Int , b: Int , c: Int) = a + b + c //default values with functions fun sum(a: Int , b: Int , c: Int , d: Int = 1) = a + b + c + d
  • 27. Class - big picture class Person(pName: String) { var name: String = "" var age: Int = -1 init { this.name = pName } constructor(pName: String , pAge: Int) : this(pName) { this.age = pAge } fun greet(): String { return "Hello $name" }
  • 28. Class - big picture class Person(pName: String) { var name: String = "" var age: Int = -1 init { this.name = pName } constructor(pName: String , pAge: Int) : this(pName) { this.age = pAge } fun greet(): String { return "Hello $name" } // Instance , we call the constructor as if it were a //regular function val person = Person() val me = Person("Adit") // Kotlin - has no new keyword
  • 29. Code // The full syntax for declaring a property is private var age:Int =0 get() = field set(value) { if(value>0) field = value } internal fun sum(first: Int , second: Int): Int { return first + second } Access modifier Keyword Name Param name Param type Return type
  • 30. Code // Full syntax internal fun sum(first: Int , second: Int): Int { return first + second } // Omit access modifier fun sum(first: Int , second: Int): Int { return first + second } // Inline return fun sum(first: Int , second: Int): Int = first + second // Omit return type fun sum(first: Int , second: Int) = first + second // As a type val sum - { first : Int, second: Int -> first + second }
  • 31. Higher order functions • Functions which return a function or take a function as a parameter • Used via Lambdas • Java 6 support
  • 32. NULL SAFETY No more Kotlin’s type system is aimed to eliminate this forever.
  • 33. Null Safety var a: String = "abc" a = null // compilation error var b: String? = "abc" b = null // ok // what about this ? val l = a.length // Promise no NPE crash val l = b.length // error: b can be null
  • 34. Null Safety // You could explicitly check if b is null , and handle the options separately val l = if (b!= null) b.length else -1 // Or ... val length = b?.length // Even better val listWithNulls: List<String?> = listOf("A",null) for (item in listWithNulls) { item?.let { println(it) } // prints A ignores null
  • 35. Nullability • In Java, the NullPointerException is one of the biggest headache’s • Kotlin , ‘null’ is part of the type system • We can explicitly declare a property , with nullable value • For each function, we can declare whether it returns a nullable value • Goodbye, NullPointerException
  • 36. Data classes public class Movie { private String name; private String posterImgUrl; private float rating; public Movie(String name, String imageUrl, float rating) { this.name = name; this.posterImgUrl = imageUrl; this.rating = rating; } // Getters and setters // equals and hashCode // toString() }
  • 37. Data classes // Just use the keyword 'data' and see the magic data class Movie(val name: String , val imgUrl: String , val rating: Float) val inception = Movie("Inception","http:// inception.com/poster.jpg",4.2) print(inception.name) print(inception.imgUrl) print(inception.rating) // Pretty print print(inception.toString()) // Copy object val inceptionTwo = inception.copy(imgUrl= "http:// imageUrl.com/inception2.png")
  • 38. Fun tricks fun evaluateObject(obj: Any): String { return when(obj){ is String -> "String it is , ahoy !!" is Int -> "Give me the 8 ball" else -> "Object is in space" } } fun ImageView.loadUrl(url: String) { Glide.with(context).load(url).into(this) }
  • 39. Extensions public static boolean isTuesday(Date date) { return date.getDay() == 2; } boolean tuesdayBool = DateUtils.isTuesday(date); fun Date.isTuesday(): Boolean { return getDay() ==2 } val dateToCheck = Date() println(date.isTuesday())
  • 40. Lambdas myButton.setOnClickListener { navigateToDetail() } fun apply(one: Int , two: Int , func: (Int, Int) -> Int): Int{ return func(one,two) } println(apply(1, 2, { a, b -> a * b })) println(apply(1, 2, { a, b -> a * 2 - 3 * b })) Higher order Functions
  • 41. if (obj instanceOf MyType) { ((MyType)obj).getXValue(); } else { // Oh no do more } Smart Casting if (obj is MyType) { obj.getXValue() } else { // Oh no do more }
  • 42. … and More • Visibility Modifiers • Companion Objects • Nested, Sealed Classes • Generics • Coroutines • Operator overloading • Exceptions • Annotations • Reflection • and more
  • 43. … and Even More • Infix extension methods • Interfaces • Interface Delegation • Property Delegation • Destructuring • Safe Singletons • Init blocks • Enums • Multiline Strings • Tail recursion
  • 44. CODE ❤ Kotlin Try Kotlin online https://goo.gl/z9Hhq6 https://fabiomsr.github.io/from-java-to-kotlin/
  • 45. QnA