SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Kurt Renzo Acosta
Research and Development
Engineer for Mobile Apps
● Kotlin is a Russian Island
● Statically-typed Programming Language
● Made by JetBrains
● Started in 2011
● Open Source
What is Kotlin?
Why Kotlin?
● Modern. Expressive. Safe
● Readable. Concise
● 100% Interoperable with
Java
● Multiplatform
Java
Compiler
Kotlin
Compiler
Bytecode
Java
Kotlin
Kotlin
Compiler
JVM
Kotlin
JSNative
Tools to use for Kotlin
Apps that use Kotlin
Kotlin Java
Basic Syntax - Variables
var hello = "Hello"
var world: String = "World"
val helloWorld = "Hello World!"
String hello = "Hello";
String world = "World";
final String helloWorld
= "Hello World!";
Kotlin Java
Basic Syntax - Comments
// This is a comment
/*
* This is also a comment
*/
// This is a comment
/*
* This is also a comment
*/
Kotlin Java
Basic Syntax - If-else
if (a > b) {
println("a")
} else if (b > a) {
println("b")
} else println("c")
if (a > b) {
System.out.println("a");
} else if (b > a) {
System.out.println("b");
} else println("c")
Kotlin Java
Basic Syntax - Switch
when (obj) {
"1st" -> println("First")
"2nd" -> println("Second")
else -> println("Third")
}
switch(obj){
case "1st":
System.out.println("First");
break;
case "2nd":
System.out.println("Second");
break;
default:
System.out.println("Third");
}
Kotlin Java
Basic Syntax - For Loops
for(x in 1..10){
// ...
}
for(item in items){
// ...
}
for(x in 10 downTo 0){
// ...
}
for((key, value) in map){
// ...
for(int i = 0; i < list.length; i++){
// ...
}
for(Object i : list){
// ...
}
for(Entry i : map){
String key = i.key;
String value = i.value;
// ...
}
Kotlin Java
Basic Syntax - While Loops
while(it.hasNext()){
println(it)
}
do{
// This
} while (condition)
while(it.hasNext()){
System.out.println(it);
}
do{
// This
} while (condition);
Kotlin Java
Kotlin Features - Classes
class Model(var property: Object)
val model = Model()
model.property = "An Object"
val property = model.property
class Model {
private Object property;
Object getProperty() {
return property;
}
void setProperty(Object property) {
this.property = property;
}
}
Model model = new Model();
model.setProperty("An Object");
Object property = model.getProperty();
Kotlin Java
Kotlin Features - Data Classes
data class Model(var property: Object) class Model {
Object property;
Model(Object property){
this.property = property;
}
void setProperty(Object property) {
this.property = property;
}
Object getProperty() {
return property;
}
void equals()(...) {
...
}
}
Kotlin Java
Kotlin Features - Objects
object Singleton {
var property
}
var property: Object = Singleton.property
class Singleton {
public Object property;
private static Singleton INSTANCE;
public static Singleton getInstance(){
if(INSTANCE == null) {
INSTANCE = new Singleton();
}
return INSTANCE;
}
}
Object property =
Singleton.getInstance().property;
Kotlin Java
Kotlin Features - Objects
var anonymousClass = object {
var x = 5
var y = 5
}
val num = anonymousClass.x
class NotAnonymousClass {
private int x = 5;
private int y = 5;
}
NotAnonymousClass obj =
new NotAnonymousClass();
int x = obj.x;
int y = obj.y;
Kotlin Features - Objects
class ClassWithSingleton {
object Singleton {
var property
}
}
val property =
ClassWithSingleton.Singleton.property
class ClassWithSingleton {
companion object {
var property
}
}
val property = ClassWithSingleton.property
Kotlin Java
Kotlin Features - Null Safety
var notNullable: String
var nullable: String?
fun main(args: Array<String>) {
notNullable = null //Error
notNullable = "Hi" //OK
nullable = null //OK
nullable = "Hi" //OK
}
String nullable;
public static void main(String[] args){
nullable = null; //OK
nullable = "HI"; //OK
}
Kotlin Java
Kotlin Features - Null Safety
var nullable: String?
fun main(args: Array<String>) {
var length = nullable?.length
var forceLength = nullable!!.length
length = nullable.length ?: 0
}
String nullable;
public static void main(String[] args){
int length;
if(nullable != null) {
length = nullable.length();
}
length = nullable != null ?
nullable.length() : 0;
}
Kotlin Features - lateinit
var lateString: String = null //Error
fun main(args: Array<String>) {
lateString = "Hello!"
}
lateinit var lateString: String
fun main(args: Array<String>) {
lateString = "Hello!"
}
Kotlin Features - lazy loading
var lateString: String = null //Error
fun main(args: Array<String>) {
lateString = "Hello!"
}
val lateString: String by lazy { "Hello!" }
Kotlin Features - lazy loading
val greeting: String = null //Error
fun main(args: Array<String>) {
val name = "Kurt"
greeting = "Hello " + name + "!"
}
val greeting: String by lazy {
val name = "Kurt"
"Hello " + name + "!"
}
Kotlin Features - String Interpolation
val greeting: String = null //Error
fun main(args: Array<String>) {
val name = "Kurt"
greeting = "Hello $name!"
}
val greeting: String by lazy {
val name = "Kurt"
"Hello $name!"
}
Kotlin Features - Named Parameters
fun something(a: Boolean, b: Boolean, c: Boolean, d: Boolean){
return true
}
something(
a = true,
b = true,
c = true,
d = true
)
something(
d = true,
c = true,
b = true,
a = true
)
Kotlin Java
Kotlin Features - Default Parameters
fun something(
a: Boolean,
b: Boolean,
c: Boolean = false,
d: Boolean = true
){
return true
}
something(
a = true,
b = true,
)
something(
a = true,
b = true,
c = true
)
Boolean something(Boolean a, Boolean b,
Boolean c, Boolean d) {
return true;
}
Boolean something(Boolean a, Boolean b) {
return something(a, b, false, true);
}
Boolean something(Boolean a, Boolean b,
Boolean c) {
return something(a, b, c, true);
}
something(true, true);
Kotlin Java
Kotlin Features - Extension Functions
fun Int.percent(percentage: Int): Int {
return this * (percentage / 100);
}
val num = 100;
num.percent(5)
class IntUtil {
int percent(int value, int percentage) {
return value * (percentage / 100);
}
}
int num = 100;
IntUtil util = new IntUtil();
util.percent(num, 5);
Kotlin Java
Kotlin Features - Infix Functions
Infix fun Int.percentOf(value: Int): Int {
return value * (this / 100);
}
val num = 100;
5 percentOf num
class IntUtil {
int percentOf(int value, int percentage) {
return value * (percentage / 100);
}
}
int num = 100;
IntUtil util = new IntUtil();
util.percentOf(num, 5);
Kotlin Features - Single-Expression Functions
fun sum(x: Int, y: Int): Int {
return x + y
}
fun checkAndroidVersion(apiLevel: Int):
String {
return when(apiLevel) {
26 -> "Oreo"
25 -> "Nougat"
23 -> "Marshmallow"
21 -> "Lollipop"
...
}
}
fun sum(x: Int, y: Int): Int = x + y
fun checkAndroidVersion(apiLevel: Int): =
when(apiLevel) {
26 -> "Oreo"
25 -> "Nougat"
23 -> "Marshmallow"
21 -> "Lollipop"
...
}
}
Kotlin Java
Kotlin Features - Operator Overloading
class Point(val x: Int, val y: Int) {
...
operator fun plus(other: Point): P =
Point(x + other.x, y + other.y)
}
val point1 = Point(5, 10)
val point2 = Point(10, 20)
val point3 = point1 + point2
class Point {
int x;
int y;
...
Point plus(Point point) {
return new Point(this.x + point.x, this.y +
point.y);
}
}
Point point1 = new Point(5, 10);
Point point2 = new Point(16, 15);
Point point3 = point1.plus(point2);
Kotlin Java
Kotlin Features - Higher-Order Functions
fun doIfLollipop(func: () -> Unit) {
if(versionIsLollipop){
func()
}
}
doIfLollipop { println("I'm a Lollipop!") }
void doIfLollipop(Runnable callback) {
if(versionIsLollipop){
callback.run();
}
}
doIfLollipop(new Runnable() {
@Override
public void run() {
System.out.println("I'm a Lollipop!");
}
});
Kotlin Java
Kotlin Features - Higher-Order Functions
val list: List<Int> =
listOf(1,3,2,4,16,15,32)
list
.filter { it % 2 == 0 }
.map { it * 10 }
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(5);
list.add(3);
list.add(8);
list.add(14);
List<Integer> filteredList = new ArrayList<>();
for(int i = 0; i < list.size(); i++){
if(list.get(i) % 2 == 0){
filteredList.add(list.get(i) * 10);
}
}
Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI Ajinkya Saswade
 
Jetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on AndroidJetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on AndroidNelson Glauber Leal
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Simplilearn
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin courseGoogleDevelopersLeba
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndreas Jakl
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlinvriddhigupta
 
Try Jetpack Compose
Try Jetpack ComposeTry Jetpack Compose
Try Jetpack ComposeLutasLin
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptxGDSCVJTI
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializableSourabh Sahu
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourMatthew Clarke
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutinesRoman Elizarov
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack TutorialSimplilearn
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react nativeModusJesus
 

Was ist angesagt? (20)

Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI
 
Jetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on AndroidJetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on Android
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin course
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
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
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlin
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
 
Try Jetpack Compose
Try Jetpack ComposeTry Jetpack Compose
Try Jetpack Compose
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning Tour
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react native
 

Ähnlich wie Kotlin on android

Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlinAdit Lal
 
Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Tobias Schneck
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android developmentAdit Lal
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to KotlinShine Joseph
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
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 SurabayaDILo Surabaya
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdfAndrey Breslav
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Effective Java and Kotlin
Effective Java and KotlinEffective Java and Kotlin
Effective Java and Kotlin경주 전
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorTrayan Iliev
 

Ähnlich wie Kotlin on android (20)

Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
Kotlin
KotlinKotlin
Kotlin
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Kotlin wonderland
Kotlin wonderlandKotlin wonderland
Kotlin wonderland
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
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
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Effective Java and Kotlin
Effective Java and KotlinEffective Java and Kotlin
Effective Java and Kotlin
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 

Kürzlich hochgeladen

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 

Kürzlich hochgeladen (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 

Kotlin on android

  • 1.
  • 2. Kurt Renzo Acosta Research and Development Engineer for Mobile Apps
  • 3. ● Kotlin is a Russian Island ● Statically-typed Programming Language ● Made by JetBrains ● Started in 2011 ● Open Source What is Kotlin?
  • 4. Why Kotlin? ● Modern. Expressive. Safe ● Readable. Concise ● 100% Interoperable with Java ● Multiplatform
  • 7. Tools to use for Kotlin
  • 8. Apps that use Kotlin
  • 9. Kotlin Java Basic Syntax - Variables var hello = "Hello" var world: String = "World" val helloWorld = "Hello World!" String hello = "Hello"; String world = "World"; final String helloWorld = "Hello World!";
  • 10. Kotlin Java Basic Syntax - Comments // This is a comment /* * This is also a comment */ // This is a comment /* * This is also a comment */
  • 11. Kotlin Java Basic Syntax - If-else if (a > b) { println("a") } else if (b > a) { println("b") } else println("c") if (a > b) { System.out.println("a"); } else if (b > a) { System.out.println("b"); } else println("c")
  • 12. Kotlin Java Basic Syntax - Switch when (obj) { "1st" -> println("First") "2nd" -> println("Second") else -> println("Third") } switch(obj){ case "1st": System.out.println("First"); break; case "2nd": System.out.println("Second"); break; default: System.out.println("Third"); }
  • 13. Kotlin Java Basic Syntax - For Loops for(x in 1..10){ // ... } for(item in items){ // ... } for(x in 10 downTo 0){ // ... } for((key, value) in map){ // ... for(int i = 0; i < list.length; i++){ // ... } for(Object i : list){ // ... } for(Entry i : map){ String key = i.key; String value = i.value; // ... }
  • 14. Kotlin Java Basic Syntax - While Loops while(it.hasNext()){ println(it) } do{ // This } while (condition) while(it.hasNext()){ System.out.println(it); } do{ // This } while (condition);
  • 15. Kotlin Java Kotlin Features - Classes class Model(var property: Object) val model = Model() model.property = "An Object" val property = model.property class Model { private Object property; Object getProperty() { return property; } void setProperty(Object property) { this.property = property; } } Model model = new Model(); model.setProperty("An Object"); Object property = model.getProperty();
  • 16. Kotlin Java Kotlin Features - Data Classes data class Model(var property: Object) class Model { Object property; Model(Object property){ this.property = property; } void setProperty(Object property) { this.property = property; } Object getProperty() { return property; } void equals()(...) { ... } }
  • 17. Kotlin Java Kotlin Features - Objects object Singleton { var property } var property: Object = Singleton.property class Singleton { public Object property; private static Singleton INSTANCE; public static Singleton getInstance(){ if(INSTANCE == null) { INSTANCE = new Singleton(); } return INSTANCE; } } Object property = Singleton.getInstance().property;
  • 18. Kotlin Java Kotlin Features - Objects var anonymousClass = object { var x = 5 var y = 5 } val num = anonymousClass.x class NotAnonymousClass { private int x = 5; private int y = 5; } NotAnonymousClass obj = new NotAnonymousClass(); int x = obj.x; int y = obj.y;
  • 19. Kotlin Features - Objects class ClassWithSingleton { object Singleton { var property } } val property = ClassWithSingleton.Singleton.property class ClassWithSingleton { companion object { var property } } val property = ClassWithSingleton.property
  • 20. Kotlin Java Kotlin Features - Null Safety var notNullable: String var nullable: String? fun main(args: Array<String>) { notNullable = null //Error notNullable = "Hi" //OK nullable = null //OK nullable = "Hi" //OK } String nullable; public static void main(String[] args){ nullable = null; //OK nullable = "HI"; //OK }
  • 21. Kotlin Java Kotlin Features - Null Safety var nullable: String? fun main(args: Array<String>) { var length = nullable?.length var forceLength = nullable!!.length length = nullable.length ?: 0 } String nullable; public static void main(String[] args){ int length; if(nullable != null) { length = nullable.length(); } length = nullable != null ? nullable.length() : 0; }
  • 22. Kotlin Features - lateinit var lateString: String = null //Error fun main(args: Array<String>) { lateString = "Hello!" } lateinit var lateString: String fun main(args: Array<String>) { lateString = "Hello!" }
  • 23. Kotlin Features - lazy loading var lateString: String = null //Error fun main(args: Array<String>) { lateString = "Hello!" } val lateString: String by lazy { "Hello!" }
  • 24. Kotlin Features - lazy loading val greeting: String = null //Error fun main(args: Array<String>) { val name = "Kurt" greeting = "Hello " + name + "!" } val greeting: String by lazy { val name = "Kurt" "Hello " + name + "!" }
  • 25. Kotlin Features - String Interpolation val greeting: String = null //Error fun main(args: Array<String>) { val name = "Kurt" greeting = "Hello $name!" } val greeting: String by lazy { val name = "Kurt" "Hello $name!" }
  • 26. Kotlin Features - Named Parameters fun something(a: Boolean, b: Boolean, c: Boolean, d: Boolean){ return true } something( a = true, b = true, c = true, d = true ) something( d = true, c = true, b = true, a = true )
  • 27. Kotlin Java Kotlin Features - Default Parameters fun something( a: Boolean, b: Boolean, c: Boolean = false, d: Boolean = true ){ return true } something( a = true, b = true, ) something( a = true, b = true, c = true ) Boolean something(Boolean a, Boolean b, Boolean c, Boolean d) { return true; } Boolean something(Boolean a, Boolean b) { return something(a, b, false, true); } Boolean something(Boolean a, Boolean b, Boolean c) { return something(a, b, c, true); } something(true, true);
  • 28. Kotlin Java Kotlin Features - Extension Functions fun Int.percent(percentage: Int): Int { return this * (percentage / 100); } val num = 100; num.percent(5) class IntUtil { int percent(int value, int percentage) { return value * (percentage / 100); } } int num = 100; IntUtil util = new IntUtil(); util.percent(num, 5);
  • 29. Kotlin Java Kotlin Features - Infix Functions Infix fun Int.percentOf(value: Int): Int { return value * (this / 100); } val num = 100; 5 percentOf num class IntUtil { int percentOf(int value, int percentage) { return value * (percentage / 100); } } int num = 100; IntUtil util = new IntUtil(); util.percentOf(num, 5);
  • 30. Kotlin Features - Single-Expression Functions fun sum(x: Int, y: Int): Int { return x + y } fun checkAndroidVersion(apiLevel: Int): String { return when(apiLevel) { 26 -> "Oreo" 25 -> "Nougat" 23 -> "Marshmallow" 21 -> "Lollipop" ... } } fun sum(x: Int, y: Int): Int = x + y fun checkAndroidVersion(apiLevel: Int): = when(apiLevel) { 26 -> "Oreo" 25 -> "Nougat" 23 -> "Marshmallow" 21 -> "Lollipop" ... } }
  • 31. Kotlin Java Kotlin Features - Operator Overloading class Point(val x: Int, val y: Int) { ... operator fun plus(other: Point): P = Point(x + other.x, y + other.y) } val point1 = Point(5, 10) val point2 = Point(10, 20) val point3 = point1 + point2 class Point { int x; int y; ... Point plus(Point point) { return new Point(this.x + point.x, this.y + point.y); } } Point point1 = new Point(5, 10); Point point2 = new Point(16, 15); Point point3 = point1.plus(point2);
  • 32. Kotlin Java Kotlin Features - Higher-Order Functions fun doIfLollipop(func: () -> Unit) { if(versionIsLollipop){ func() } } doIfLollipop { println("I'm a Lollipop!") } void doIfLollipop(Runnable callback) { if(versionIsLollipop){ callback.run(); } } doIfLollipop(new Runnable() { @Override public void run() { System.out.println("I'm a Lollipop!"); } });
  • 33. Kotlin Java Kotlin Features - Higher-Order Functions val list: List<Int> = listOf(1,3,2,4,16,15,32) list .filter { it % 2 == 0 } .map { it * 10 } List<Integer> list = new ArrayList<>(); list.add(1); list.add(5); list.add(3); list.add(8); list.add(14); List<Integer> filteredList = new ArrayList<>(); for(int i = 0; i < list.size(); i++){ if(list.get(i) % 2 == 0){ filteredList.add(list.get(i) * 10); } }
  • 34. Q&A