SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
KOTLIN
● Primary target JVM
● Javascript
● Compiled in Java byte code
● Created for industry
Core goals is 100% Java interoperability.
KOTLIN main features
Concise
Drastically reduce the amount of
boilerplate code you need to write.
Safe
Avoid entire classes of errors such
as null pointer exceptions.
Interoperable
Leverage existing frameworks and
libraries of the JVM with 100% Java
Interoperability.
data class Person(
var name: String,
var surname: String,
var age: Int)
Create a POJO with:
● Getters
● Setters
● equals()
● hashCode()
● toString()
● copy()
Concise
public class Person {
final String firstName;
final String lastName;
public Person(...) {
...
}
// Getters
...
// Hashcode / equals
...
// Tostring
...
// Egh...
}
KOTLIN lambdas
● must always appear between curly brackets
● if there is a single parameter then it can be referred to by it
Concise
val list = (0..49).toList()
val filtered = list
.filter({ x -> x % 2 == 0 })
val list = (0..49).toList()
val filtered = list
.filter { it % 2 == 0 }
NULL safety
// ERROR
// OK
// OK
// ERROR
NULL safety
// ERROR
NULL safety
// ERROR
SAFE CALL
NULL safety
Extend existing classes functionality
Ability to extend a class with new functionality without having to inherit from the class
● does not modify classes
● are resolved statically
Extend existing classes functionality
fun String.lastChar() = this.charAt(this.length() - 1)
// this can be omitted
fun String.lastChar() = charAt(length() - 1)
fun use(){
Val c: Char = "abc".lastChar()
}
Everything is an expression
val max = if (a > b) a else b
val hasPrefix = when(x) {
is String -> x.startsWith("prefix")
else -> false
}
when(x) {
in 1..10 -> ...
102 -> ...
else -> ...
}
boolean hasPrefix;
if (x instanceof String)
hasPrefix = x.startsWith("prefix");
else
hasPrefix = false;
switch (month) {
case 1: ... break
case 7: ... break
default: ...
}
Default Parameters
fun foo( i :Int, s: String = "", b: Boolean = true) {}
fun usage(){
foo( 1, b = false)
}
for loop
can iterate over any type that provides an iterator implementing next() and hasNext()
for (item in collection)
print(item)
for ((index, value) in array.withIndex()) {
println("the element at $index is $value")
}
Collections
● Made easy
● distinguishes between immutable and mutable collections
val numbers: MutableList = mutableListOf(1, 2, 3)
val readOnlyNumbers: List = numbers
numbers.add(4)
println(readOnlyView) // prints "[1, 2, 3, 4]"
readOnlyNumbers.clear() // -> does not compile
Java 6
// Using R.layout.activity_main from the main source set
import kotlinx.android.synthetic.main.activity_main.*
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.setText("Hello, world!")
}
}
public class MyActivity extends Activity() {
@override
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello, world!");
}
}
Kotlin Android Extensions
Extension functions
fun Fragment.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(getActivity(), message, duration).show()
}
fragment.toast("Hello world!")
Activities
startActivity( intentFor< NewActivity > ("Answer" to 42) )
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("Answer", 42);
startActivity(intent);
Functional support (Lambdas)
view.setOnClickListener { toast("Hello world!") }
View view = (View) findViewById(R.id.view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(this, "asdf", Toast.LENGTH_LONG)
.show();
}
});
Dynamic Layout
scrollView {
linearLayout(LinearLayout.VERTICAL) {
val label = textView("?")
button("Click me!") {
label.setText("Clicked!")
}
editText("Edit me!")
// codice koltin
// ...
}
}.style(...)
?
Click me!
Edit me!
Easily mixed with Java
● Do not have to convert everything at once
● You can convert little portions
● Write kotlin code over the existing Java code
Everything still works
Kotlin costs nothing to adopt
● It’s open source
● There’s a high quality, one-click Java to Kotlin converter tool
● Can use all existing Java frameworks and libraries
● It integrates with Maven, Gradle and other build systems.
● Great for Android, compiles for java 6 byte code
● Very small runtime library 924 KB
Kotlin usefull links
● A very well done documentation : Tutorial, Videos
● Kotlin Koans online
● Constantly updating in Github, kotlin-projects
● Talks: Kotlin in Action, Kotlin on Android
What Java has that Kotlin does not
https://kotlinlang.org/docs/reference/comparison-to-java.html
Primitive Types
Everything is an object
we can call member functions and properties on any variable.
What Java has that Kotlin does not
val a: Int? = 1
val b: Long? = a
print(a == b)
Primitive Types
Everything is an object
we can call member functions and properties on any variable.
What Java has that Kotlin does not
val a: Int? = 1
val b: Long? = a
print(a == b) // FALSE //
Primitive Types
Everything is an object
we can call member functions and properties on any variable.
What Java has that Kotlin does not
val b: Byte = 1
val i: Int = b
val i: Int = b.toInt()
val a: Int? = 1
val b: Long? = a
print(a == b) // FALSE //
Primitive Types
Everything is an object
we can call member functions and properties on any variable.
What Java has that Kotlin does not
val b: Byte = 1
val i: Int = b // ERROR //
val i: Int = b.toInt() // OK //
val a: Int? = 1
val b: Long? = a
print(a == b) // FALSE //
Static Members
class MyClass {
companion object Factory {
fun create(): MyClass = MyClass()
}
}
val instance = MyClass.create()
What Java has that Kotlin does not
Singleton
object MyClass {
// ....
}
Gradle Goes Kotlin
https://kotlinlang.org/docs/reference/using-gradle.html
Thank You
Erinda Jaupaj
@ErindaJaupi

Mais conteúdo relacionado

Mais procurados

Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android ApplicationsRody Middelkoop
 
Introduction to kotlin coroutines
Introduction to kotlin coroutinesIntroduction to kotlin coroutines
Introduction to kotlin coroutinesNAVER Engineering
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesLauren Yew
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin OverviewEkta Raj
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show fileSaurabh Tripathi
 
Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | EdurekaEdureka!
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationSeven Peaks Speaks
 
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
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest MatchersShai Yallin
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized projectFabio Collini
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKai Koenig
 

Mais procurados (20)

Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin
KotlinKotlin
Kotlin
 
Introduction to kotlin coroutines
Introduction to kotlin coroutinesIntroduction to kotlin coroutines
Introduction to kotlin coroutines
 
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
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | Edureka
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android application
 
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
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
Java vs kotlin
Java vs kotlin Java vs kotlin
Java vs kotlin
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized project
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 

Semelhante a A quick and fast intro to Kotlin

Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance Coder Tech
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsJigar Gosar
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to KotlinMagda Miu
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехСбертех | SberTech
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptxadityakale2110
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoArnaud Giuliani
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxIan Robertson
 
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 nigeriansjunaidhasan17
 
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
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
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
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java DevelopersChristoph Pickl
 

Semelhante a A quick and fast intro to Kotlin (20)

Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
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
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.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
 
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
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Kotlin
KotlinKotlin
Kotlin
 
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...
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
Kotlin Basic & Android Programming
Kotlin Basic & Android ProgrammingKotlin Basic & Android Programming
Kotlin Basic & Android Programming
 

Mais de XPeppers

Yagni, You aren't gonna need it
Yagni, You aren't gonna need itYagni, You aren't gonna need it
Yagni, You aren't gonna need itXPeppers
 
Jenkins Shared Libraries
Jenkins Shared LibrariesJenkins Shared Libraries
Jenkins Shared LibrariesXPeppers
 
The Continuous Delivery process
The Continuous Delivery processThe Continuous Delivery process
The Continuous Delivery processXPeppers
 
How Agile Dev Teams work
How Agile Dev Teams workHow Agile Dev Teams work
How Agile Dev Teams workXPeppers
 
The Phoenix Project: un romanzo sull'IT
The Phoenix Project: un romanzo sull'ITThe Phoenix Project: un romanzo sull'IT
The Phoenix Project: un romanzo sull'ITXPeppers
 
Metriche per finanziare il cambiamento
Metriche per finanziare il cambiamentoMetriche per finanziare il cambiamento
Metriche per finanziare il cambiamentoXPeppers
 
How do you handle renaming of a resource in RESTful way
How do you handle renaming of a resource in RESTful wayHow do you handle renaming of a resource in RESTful way
How do you handle renaming of a resource in RESTful wayXPeppers
 
La tecnica del pomodoro - Come viene adottata in XPeppers
La tecnica del pomodoro - Come viene adottata in XPeppersLa tecnica del pomodoro - Come viene adottata in XPeppers
La tecnica del pomodoro - Come viene adottata in XPeppersXPeppers
 
Collective code ownership in Extreme Programming
Collective code ownership in Extreme ProgrammingCollective code ownership in Extreme Programming
Collective code ownership in Extreme ProgrammingXPeppers
 
What is Agile?
What is Agile?What is Agile?
What is Agile?XPeppers
 
Improve your TDD skills
Improve your TDD skillsImprove your TDD skills
Improve your TDD skillsXPeppers
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructureXPeppers
 
Banche agili un ossimoro?
Banche agili un ossimoro?Banche agili un ossimoro?
Banche agili un ossimoro?XPeppers
 
Hiring Great People: how we improved our recruiting process to build and grow...
Hiring Great People: how we improved our recruiting process to build and grow...Hiring Great People: how we improved our recruiting process to build and grow...
Hiring Great People: how we improved our recruiting process to build and grow...XPeppers
 
Continuous Delivery in Java
Continuous Delivery in JavaContinuous Delivery in Java
Continuous Delivery in JavaXPeppers
 
Life in XPeppers
Life in XPeppersLife in XPeppers
Life in XPeppersXPeppers
 
Cloud e innovazione
Cloud e innovazioneCloud e innovazione
Cloud e innovazioneXPeppers
 
Company culture slides
Company culture slidesCompany culture slides
Company culture slidesXPeppers
 
Agileday2013 Bravi si diventa
Agileday2013 Bravi si diventaAgileday2013 Bravi si diventa
Agileday2013 Bravi si diventaXPeppers
 
Agileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaAgileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaXPeppers
 

Mais de XPeppers (20)

Yagni, You aren't gonna need it
Yagni, You aren't gonna need itYagni, You aren't gonna need it
Yagni, You aren't gonna need it
 
Jenkins Shared Libraries
Jenkins Shared LibrariesJenkins Shared Libraries
Jenkins Shared Libraries
 
The Continuous Delivery process
The Continuous Delivery processThe Continuous Delivery process
The Continuous Delivery process
 
How Agile Dev Teams work
How Agile Dev Teams workHow Agile Dev Teams work
How Agile Dev Teams work
 
The Phoenix Project: un romanzo sull'IT
The Phoenix Project: un romanzo sull'ITThe Phoenix Project: un romanzo sull'IT
The Phoenix Project: un romanzo sull'IT
 
Metriche per finanziare il cambiamento
Metriche per finanziare il cambiamentoMetriche per finanziare il cambiamento
Metriche per finanziare il cambiamento
 
How do you handle renaming of a resource in RESTful way
How do you handle renaming of a resource in RESTful wayHow do you handle renaming of a resource in RESTful way
How do you handle renaming of a resource in RESTful way
 
La tecnica del pomodoro - Come viene adottata in XPeppers
La tecnica del pomodoro - Come viene adottata in XPeppersLa tecnica del pomodoro - Come viene adottata in XPeppers
La tecnica del pomodoro - Come viene adottata in XPeppers
 
Collective code ownership in Extreme Programming
Collective code ownership in Extreme ProgrammingCollective code ownership in Extreme Programming
Collective code ownership in Extreme Programming
 
What is Agile?
What is Agile?What is Agile?
What is Agile?
 
Improve your TDD skills
Improve your TDD skillsImprove your TDD skills
Improve your TDD skills
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
 
Banche agili un ossimoro?
Banche agili un ossimoro?Banche agili un ossimoro?
Banche agili un ossimoro?
 
Hiring Great People: how we improved our recruiting process to build and grow...
Hiring Great People: how we improved our recruiting process to build and grow...Hiring Great People: how we improved our recruiting process to build and grow...
Hiring Great People: how we improved our recruiting process to build and grow...
 
Continuous Delivery in Java
Continuous Delivery in JavaContinuous Delivery in Java
Continuous Delivery in Java
 
Life in XPeppers
Life in XPeppersLife in XPeppers
Life in XPeppers
 
Cloud e innovazione
Cloud e innovazioneCloud e innovazione
Cloud e innovazione
 
Company culture slides
Company culture slidesCompany culture slides
Company culture slides
 
Agileday2013 Bravi si diventa
Agileday2013 Bravi si diventaAgileday2013 Bravi si diventa
Agileday2013 Bravi si diventa
 
Agileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaAgileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastruttura
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

A quick and fast intro to Kotlin

  • 1.
  • 2. KOTLIN ● Primary target JVM ● Javascript ● Compiled in Java byte code ● Created for industry Core goals is 100% Java interoperability.
  • 3. KOTLIN main features Concise Drastically reduce the amount of boilerplate code you need to write. Safe Avoid entire classes of errors such as null pointer exceptions. Interoperable Leverage existing frameworks and libraries of the JVM with 100% Java Interoperability.
  • 4. data class Person( var name: String, var surname: String, var age: Int) Create a POJO with: ● Getters ● Setters ● equals() ● hashCode() ● toString() ● copy() Concise public class Person { final String firstName; final String lastName; public Person(...) { ... } // Getters ... // Hashcode / equals ... // Tostring ... // Egh... }
  • 5. KOTLIN lambdas ● must always appear between curly brackets ● if there is a single parameter then it can be referred to by it Concise val list = (0..49).toList() val filtered = list .filter({ x -> x % 2 == 0 }) val list = (0..49).toList() val filtered = list .filter { it % 2 == 0 }
  • 10. Extend existing classes functionality Ability to extend a class with new functionality without having to inherit from the class ● does not modify classes ● are resolved statically
  • 11. Extend existing classes functionality fun String.lastChar() = this.charAt(this.length() - 1) // this can be omitted fun String.lastChar() = charAt(length() - 1) fun use(){ Val c: Char = "abc".lastChar() }
  • 12. Everything is an expression val max = if (a > b) a else b val hasPrefix = when(x) { is String -> x.startsWith("prefix") else -> false } when(x) { in 1..10 -> ... 102 -> ... else -> ... } boolean hasPrefix; if (x instanceof String) hasPrefix = x.startsWith("prefix"); else hasPrefix = false; switch (month) { case 1: ... break case 7: ... break default: ... }
  • 13. Default Parameters fun foo( i :Int, s: String = "", b: Boolean = true) {} fun usage(){ foo( 1, b = false) }
  • 14. for loop can iterate over any type that provides an iterator implementing next() and hasNext() for (item in collection) print(item) for ((index, value) in array.withIndex()) { println("the element at $index is $value") }
  • 15. Collections ● Made easy ● distinguishes between immutable and mutable collections val numbers: MutableList = mutableListOf(1, 2, 3) val readOnlyNumbers: List = numbers numbers.add(4) println(readOnlyView) // prints "[1, 2, 3, 4]" readOnlyNumbers.clear() // -> does not compile
  • 17. // Using R.layout.activity_main from the main source set import kotlinx.android.synthetic.main.activity_main.* class MyActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.setText("Hello, world!") } } public class MyActivity extends Activity() { @override void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView); textView.setText("Hello, world!"); } } Kotlin Android Extensions
  • 18. Extension functions fun Fragment.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) { Toast.makeText(getActivity(), message, duration).show() } fragment.toast("Hello world!")
  • 19. Activities startActivity( intentFor< NewActivity > ("Answer" to 42) ) Intent intent = new Intent(this, NewActivity.class); intent.putExtra("Answer", 42); startActivity(intent);
  • 20. Functional support (Lambdas) view.setOnClickListener { toast("Hello world!") } View view = (View) findViewById(R.id.view); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(this, "asdf", Toast.LENGTH_LONG) .show(); } });
  • 21. Dynamic Layout scrollView { linearLayout(LinearLayout.VERTICAL) { val label = textView("?") button("Click me!") { label.setText("Clicked!") } editText("Edit me!") // codice koltin // ... } }.style(...) ? Click me! Edit me!
  • 22. Easily mixed with Java ● Do not have to convert everything at once ● You can convert little portions ● Write kotlin code over the existing Java code Everything still works
  • 23. Kotlin costs nothing to adopt ● It’s open source ● There’s a high quality, one-click Java to Kotlin converter tool ● Can use all existing Java frameworks and libraries ● It integrates with Maven, Gradle and other build systems. ● Great for Android, compiles for java 6 byte code ● Very small runtime library 924 KB
  • 24. Kotlin usefull links ● A very well done documentation : Tutorial, Videos ● Kotlin Koans online ● Constantly updating in Github, kotlin-projects ● Talks: Kotlin in Action, Kotlin on Android
  • 25. What Java has that Kotlin does not https://kotlinlang.org/docs/reference/comparison-to-java.html
  • 26. Primitive Types Everything is an object we can call member functions and properties on any variable. What Java has that Kotlin does not val a: Int? = 1 val b: Long? = a print(a == b)
  • 27. Primitive Types Everything is an object we can call member functions and properties on any variable. What Java has that Kotlin does not val a: Int? = 1 val b: Long? = a print(a == b) // FALSE //
  • 28. Primitive Types Everything is an object we can call member functions and properties on any variable. What Java has that Kotlin does not val b: Byte = 1 val i: Int = b val i: Int = b.toInt() val a: Int? = 1 val b: Long? = a print(a == b) // FALSE //
  • 29. Primitive Types Everything is an object we can call member functions and properties on any variable. What Java has that Kotlin does not val b: Byte = 1 val i: Int = b // ERROR // val i: Int = b.toInt() // OK // val a: Int? = 1 val b: Long? = a print(a == b) // FALSE //
  • 30. Static Members class MyClass { companion object Factory { fun create(): MyClass = MyClass() } } val instance = MyClass.create() What Java has that Kotlin does not Singleton object MyClass { // .... }