SlideShare a Scribd company logo
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

More Related Content

What's hot

Kotlin
KotlinKotlin
Kotlin
Rory Preddy
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
Tomislav Homan
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
Garth Gilmour
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
Syed Awais Mazhar Bukhari
 
Aidl service
Aidl serviceAidl service
Aidl service
Anjan Debnath
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
Roman Elizarov
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
Simplilearn
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
Alexey Soshin
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
NAVER Engineering
 
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
 
Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | Edureka
Edureka!
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
National Cheng Kung University
 
Kotlin
KotlinKotlin
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
National Cheng Kung University
 
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
Andreas Jakl
 
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
takshilkunadia
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
T.M. Ishrak Hussain
 

What's hot (20)

Kotlin
KotlinKotlin
Kotlin
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Aidl service
Aidl serviceAidl service
Aidl service
 
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
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | Edureka
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Kotlin
KotlinKotlin
Kotlin
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
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
 
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
 
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
 

Similar to Kotlin on android

Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
Kurt Renzo Acosta
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
Mohamed 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 kotlin
Adit Lal
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
Oswald Campesato
 
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 development
Adit Lal
 
Kotlin
KotlinKotlin
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
Minseo Chayabanjonglerd
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
Shine Joseph
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
Squareboat
 
Kotlin wonderland
Kotlin wonderlandKotlin wonderland
Kotlin wonderland
Jedsada Tiwongvokul
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
Jedsada Tiwongvokul
 
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
 
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
Andrey Breslav
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
Adit Lal
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
MobileAcademy
 
Effective Java and Kotlin
Effective Java and KotlinEffective Java and Kotlin
Effective Java and Kotlin
경주 전
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
Elifarley Cruz
 
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
Trayan Iliev
 

Similar to 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
 

Recently uploaded

原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 

Recently uploaded (20)

原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 

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