(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
A quick and fast intro to Kotlin
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

More Related Content

What's hot

Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | Edureka
Edureka!
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
Ekta Raj
 
Kotlin
KotlinKotlin
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
Syed Awais Mazhar Bukhari
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
Abdul Rahman Masri Attal
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin course
GoogleDevelopersLeba
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
T.M. Ishrak Hussain
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
Shaul Rosenzwieg
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
Kotlin
KotlinKotlin
Kotlin
Ravi Pawar
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
Ranjith Sekar
 
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
 
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
KotlinKotlin
Kotlin
Rory Preddy
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
Dariusz Lorenc
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Java vs kotlin
Java vs kotlin Java vs kotlin
Java vs kotlin
RupaliSingh82
 

What's hot (20)

Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
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
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
 
Kotlin
KotlinKotlin
Kotlin
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
 
Android Development with Kotlin course
Android Development  with Kotlin courseAndroid Development  with Kotlin course
Android Development with Kotlin course
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
 
Kotlin
KotlinKotlin
Kotlin
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
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
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Kotlin
KotlinKotlin
Kotlin
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
Oop java
Oop javaOop java
Oop java
 
Java vs kotlin
Java vs kotlin Java vs kotlin
Java vs kotlin
 

Similar to 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 - 3
Mohamed Nabil, MSc.
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
Adit Lal
 
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 JetBrains
Jigar Gosar
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
Magda 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 - mRready
MobileAcademy
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
adityakale2110
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
Ian 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 nigerians
junaidhasan17
 
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
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
Kotlin
KotlinKotlin
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 Developers
Christoph Pickl
 
Kotlin Basic & Android Programming
Kotlin Basic & Android ProgrammingKotlin Basic & Android Programming
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
Scala ntnu
Scala ntnuScala ntnu

Similar to 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
 
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
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 

More from 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 it
XPeppers
 
Jenkins Shared Libraries
Jenkins Shared LibrariesJenkins Shared Libraries
Jenkins Shared Libraries
XPeppers
 
The Continuous Delivery process
The Continuous Delivery processThe Continuous Delivery process
The Continuous Delivery process
XPeppers
 
How Agile Dev Teams work
How Agile Dev Teams workHow Agile Dev Teams work
How Agile Dev Teams work
XPeppers
 
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
XPeppers
 
Metriche per finanziare il cambiamento
Metriche per finanziare il cambiamentoMetriche per finanziare il cambiamento
Metriche per finanziare il cambiamento
XPeppers
 
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
XPeppers
 
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
XPeppers
 
Collective code ownership in Extreme Programming
Collective code ownership in Extreme ProgrammingCollective code ownership in Extreme Programming
Collective code ownership in Extreme Programming
XPeppers
 
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 skills
XPeppers
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
XPeppers
 
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 Java
XPeppers
 
Life in XPeppers
Life in XPeppersLife in XPeppers
Life in XPeppers
XPeppers
 
Cloud e innovazione
Cloud e innovazioneCloud e innovazione
Cloud e innovazione
XPeppers
 
Company culture slides
Company culture slidesCompany culture slides
Company culture slides
XPeppers
 
Agileday2013 Bravi si diventa
Agileday2013 Bravi si diventaAgileday2013 Bravi si diventa
Agileday2013 Bravi si diventa
XPeppers
 
Agileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaAgileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastruttura
XPeppers
 

More from 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
 

Recently uploaded

INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
ScyllaDB
 
this resume for sadika shaikh bca student
this resume for sadika shaikh bca studentthis resume for sadika shaikh bca student
this resume for sadika shaikh bca student
SadikaShaikh7
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
anupriti
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
Data Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber SecurityData Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber Security
anupriti
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
Linda Zhang
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
HackersList
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
Interaction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance MetricInteraction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance Metric
ScyllaDB
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
AI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AIAI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AI
Raphaël Semeteys
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
crioux1
 

Recently uploaded (20)

INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
 
this resume for sadika shaikh bca student
this resume for sadika shaikh bca studentthis resume for sadika shaikh bca student
this resume for sadika shaikh bca student
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
Data Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber SecurityData Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber Security
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
Interaction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance MetricInteraction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance Metric
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
AI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AIAI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AI
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
 

A quick and fast intro to Kotlin

  • 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 { // .... }