SlideShare a Scribd company logo
1 of 34
Download to read offline
Kotlin
foss' a vota bona
(could be the right time)
Disclaimer
La presentazione contiene battute stupide e un
sacco di println
Chi sono
Mi chiamo Davide Cerbo e scrivo
codice brutto da quando avevo 7
anni, dal 2003 mi pagano per farlo.
C’era una volta OAK
Correva l’anno 1992 ed
iniziava Tangentopoli
C’era una volta OAK Java
Nasce nel 1995, in
America ha la patente
e da 12 mesi può bere
alcolici.
Il grande problema
Backward
compatibility
(L’arte di rompere la tua applicazione perché le
altre evolvono e la tua non può.)
JDK 1.0 (21 gennaio 1996)
JDK 1.1 (19 febbraio 1997)
J2SE 1.2 (8 dicembre 1998)
J2SE 1.3 (8 maggio 2000)
J2SE 1.4 (6 febbraio 2002)
J2SE 5.0 (30 settembre 2004)
Java SE 6 (11 dicembre 2006)
Java SE 7 (28 luglio 2011)
Java SE 8 (18 marzo 2014)
Tutte compatibili!
JVM != Java
JAVA JVM
https://dzone.com/articles/why-learn-kotlin-infographic
Dal 2010(2012) ad oggi: KOTLIN!
Kotlin is a statically-typed programming
language that runs on the Java Virtual Machine
and also can be compiled to JavaScript source
code or uses the LLVM compiler infrastructure.
Nella botte piccola c’è il vino buono
From Java to Kotlin
https://github.com/MindorksOpenSource/from-java-to-kotlin
Var o Val
var serie = “A”
var a = “Benevento in serie $serie”
val a = “Benevento in serie $serie”
Fun
fun main(args: Array<String>){
hello(“Davide, “Salerno”)
}
fun hello(name: String, city: String){
println(“Ciao $name da $city”)
}
Fun fun functions
fun hello(name: String, city : String = "Salerno") =
println("Ciao $name da $city")
hello(name=”Davide”)
hello(city=”Salerno”, name=”Valentina”)
Int.multiply(x:int) = this * 5
infix Int.multiply(x:int) = this * 5
tailrec fun factorial(accumulator: Int, n: Int): Int = if (n
== 1) accumulator else factorial(accumulator * n, n - 1)
Nella vita ci vuole Class?
open class Person(val name: String) {
init { println(“init…”) }
open fun speak() { println("Hi $name!") }
infix fun and(o: Person) = "Hi ${o.name} & ${this.name}"
}
Person(“Davide”) and Person(“Valentina”)
Equals, hashCode, toString e copy, mai più!
data class User(val name: String, val age: Int)
val davide = User(“Davide”, 35)
val davideJunior = davide.copy(age=0)
val (name, age) = davide
println("$name $age years old")
Lamb(a)da
Lambda
arrayOf("ciao", "davide").forEach { println("Hello $it!") }
val doubled = ints.map { value -> value * 2 }
val doubled = ints.map { it * 2 }
class Customer(name: String) : Person(name) {
fun forEach(action: (line: Char) -> Unit) =
name.forEach(action)
fun hello(action: (line: String) -> String) =
"Hello ${action.invoke(name)}"
}
Tu dimmi quando, quando...
fun describe(obj: Any): String = when (obj) {
1 -> "One"
"Hello" -> "Greeting"
is Long -> "Long"
!is String -> "Not a string"
else -> "Unknown"
}
describe(Person(“davide”))
Null è sicuro
var test:String = "ciao"
test = null
var test:String? = "ciao"
test = null
println(test?.length)
println(test!!.length)
val davide = User(test, 35)
val davide = User(test ?: "Mino", 35)
?:Elvis operator
A questo punto mi devo ricordare di dire che è
bello perché è semplice.
Scriviamo meno e con maggiore significato.
04 Gennaio 2017
Introducing Kotlin support
in Spring Framework 5.0
arrayOf("ciao", "davide").forEach {
println("Hello $it!") }
Deploy con Apache Tomcat
git clone git@github.com:JetBrains/kotlin-examples.git
cd kotlin-examples/tutorials/servlet-web-applications/
gradle war
curl -O http://apache.panu.it/tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.zip
unzip apache-tomcat-9.0.0.M21.zip
cp build/servlet-web-applications.war apache-tomcat-9.0.0.M21/webapp
cd apache-tomcat-9.0.0.M21/bin
./startup.sh
http://localhost:8080/servlet-web-applications/hello
Java + Kotlin (+ Maven)
Cosa ci siamo persi?
● Spring WebFlux
● Reactor
● Coroutine
● Gradle + Kotlin
● Android + Kotlin
● Javascript + Kotlin
● Native + Kotlin
● Spring 5 + Kotlin
● JUnit + Kotlin
Domande
Risorse utili
https://kotlinlang.org/docs/reference/
https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0
https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/
https://dev.to/lovis/gang-of-four-patterns-in-kotlin
https://github.com/gradle/gradle-script-kotlin
https://speakerdeck.com/sdeleuze/functional-web-applications-with-spring-and-kotlin
https://kotlinlang.org/docs/tutorials/httpservlets.html
Risorse utili

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Kotlin: foss' a vota bona (could be the right time)