SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
What’s new in
otlin
Vipul Asri
Overview
● Kotlin is a new programming language from
JetBrains
● First appeared in 2011, stable release 1.0 in Feb,
2016
● “Statically typed programming language”
● Procedural as well as Functional Programming
both
● Google announced official support for Kotlin on
Android at Google I/O, 2017
Benefits
● Kotlin compiles to JVM bytecode or JavaScript
● Kotlin programs can use all existing Java
Frameworks and Libraries
● Kotlin can be learned easily
● Automatic conversion of Java to Kotlin with
Android Studio
● Kotlin’s null-safety is great
Features
Extension Functions
fun String.removeSpaces() { … }
// call to extension function
“Hello, I am Vipul Asri”.removeSpaces()
// output
“Hello,IamVipulAsri”
Inter-operable With Java
Java code can be used inside Kotlin code and vice-versa.
class Person {
String name = “Person Nath”
public String getNameWithoutSpace() {
return name.removeSpaces();
}
}
Synthetic Extension( bye bye to findViewById() )
Java
class MainActivity extends AppCompatActivity{
TextView studentName;
@Override
protected void onCreate(Bundle
savedInstanceState) {
studentName =
findViewById(R.id.studentName);
studentName.setText("Harshit Dwivedi");
}
}
Kotlin
import
kotlinx.android.synthetic.main.activity_main.*
class KotlinActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState:
Bundle?) {
studentName.text = "Harshit" //That's it!
}
}
NPE Safety
var name_1: String = "abc"
name_1 = null // try to assign null, won’t compile.
// To allow nulls, we declare a variable as nullable string
var name_2: String? = "abc"
name_2 = null // no compilation error.
val len = name_1.length // there will be no NPE
val len = name_2.length // error: variable 'name_2' can be null
NPE Safety
1. Checking for null in conditions
val len = if (name_2 != null) name_2.length else -1
2. Safe Calls (with ?.)
name_2?.length // name_2.length if name_2 is not null, and null otherwise
3. The !! Operator (for NPE Lovers) - not-null assertion operator (!!)
val l = b!!.length // (!!) converts any value to a non-null type
// and throws an exception if the value is null
Coroutines (experimental)
● Threads can easily eat up almost a megabyte of memory.
In this context, we can call coroutines (as per the
documentation) as "lightweight" threads.
● A coroutine is sitting on an actual thread pool, which is
used for background execution.
● It only uses the resources when it needs it.
launch{}
val job = launch {
val userString = fetchUserString("1")
val user = deserializeUser(userString)
log(user.name)
}
The wrapped code is dispatched to a background thread, and
the function itself returns a Job instance, which can be used in
other coroutines to control the execution.
async{}
val user = async {
val userString = fetchUserString("1")
val user = deserializeUser(userString)
user
}.await()
The async function returns a Defered<T> instance, and calling
await() on it you can get the actual result of the computation.
Comparison
Java vs Kotlin
No semicolons
Java
System.out.println(“Hello”);
Kotlin
println(“Hello”)
Type Declaration
Java
int a = 1;
String s = “abc”;
boolean b;
Kotlin
val a: Int = 1
val s: String = “abc”
val b: Boolean
Type Inference
Java
int a = 1;
String s = “abc”;
boolean b;
Kotlin
val a = 1
val s = “abc”
val b: Boolean
Object Declaration - No ‘new’
Java
Car car = new Car();
Kotlin
val car = Car()
String templates
Java
String s = String.format(“%s
has %d apples, name,
count);
Kotlin
val s = “$name has $count
apples”
Functions
Java
String getName(Person person) {
return person.getName();
}
Kotlin
fun getName(person: Person): String {
return person.name
}
Expressions body
Java
int sum(int a , int b) {
return a+b;
}
Kotlin
val sum(a: Int , b:Int) = a+b
‘When’ Expression
Java
switch(x) {
case 1: log.info("x == 1"); break;
case 2: log.info("x == 2"); break;
default: log.info("x is neither 1 nor
2");
}
Kotlin
when (x) {
in 0,1 -> print("x is too low")
in 2..10 -> print("x is in range")
!in 10..20 -> print("x outside range")
parseInt(s) -> print("s encodes x")
is Program -> print("It's a program!")
else -> print("None of the above")
}
Ranges
Java
IntStream.rangeClosed(1, 5)
.forEach(x -> ...);
Kotlin
for (x in 1..5) { ... }
Data Classes
Java
class Address {
final String city;
Address(String n) { city = n; }
String getCity() { return city; }
void setCity(String n) { city = n; }
int equals() { ... }
hashCode() { ... }
toString() { ... }
copy() { ... } }
Kotlin
data class Address(var city:String,
var country:Country)
Kotlin 1.2
Sharing Code between
Platforms
● JavaScript target, allowing you to compile Kotlin code to JS and to run it in
your browser
● Reuse code between the JVM and JavaScript
● Business logic of your application once, and reuse it across all tiers of your
application – the backend, the browser frontend and the Android mobile app
Thank You!

Más contenido relacionado

La actualidad más candente

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyHaim Yadid
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlinAlexey Soshin
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Abu Saleh
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Hyuk Hur
 
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentSay Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentAdam Magaña
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet KotlinJieyi Wu
 
Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With KotlinGaurav sharma
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetHDR1001
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Dierk König
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCDrsebbe
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Åsa Pehrsson
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 

La actualidad más candente (20)

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"
 
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentSay Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android Development
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Java 7
Java 7Java 7
Java 7
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
Ejb3.1
Ejb3.1Ejb3.1
Ejb3.1
 
Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With Kotlin
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11
 
CODEsign 2015
CODEsign 2015CODEsign 2015
CODEsign 2015
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 

Similar a What’s new in Kotlin?

A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехСбертех | SberTech
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance Coder Tech
 
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
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of androidDJ Rausch
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better JavaNils Breunese
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlinAlexey Soshin
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentJayaprakash R
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to KotlinMagda Miu
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in KotlinLuca Guadagnini
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Davide Cerbo
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 

Similar a What’s new in Kotlin? (20)

A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
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
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
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
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better Java
 
Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 

Más de Squareboat

Squareboat Deck
Squareboat DeckSquareboat Deck
Squareboat DeckSquareboat
 
Squareboat Branding Proposal
Squareboat Branding ProposalSquareboat Branding Proposal
Squareboat Branding ProposalSquareboat
 
Squareboat Product Foundation Process
Squareboat Product Foundation ProcessSquareboat Product Foundation Process
Squareboat Product Foundation ProcessSquareboat
 
Squareboat Culture Deck
Squareboat Culture DeckSquareboat Culture Deck
Squareboat Culture DeckSquareboat
 
Squareboat Design Portfolio
Squareboat Design PortfolioSquareboat Design Portfolio
Squareboat Design PortfolioSquareboat
 
Squareboat Crew Deck
Squareboat Crew DeckSquareboat Crew Deck
Squareboat Crew DeckSquareboat
 
High Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at SquareboatHigh Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at SquareboatSquareboat
 
CTA - Call to Attention
CTA - Call to AttentionCTA - Call to Attention
CTA - Call to AttentionSquareboat
 
Tech talk on Tailwind CSS
Tech talk on Tailwind CSSTech talk on Tailwind CSS
Tech talk on Tailwind CSSSquareboat
 
What’s New in Apple World - WWDC19
What’s New in Apple World - WWDC19What’s New in Apple World - WWDC19
What’s New in Apple World - WWDC19Squareboat
 
Tech Talk on Microservices at Squareboat
Tech Talk on Microservices at SquareboatTech Talk on Microservices at Squareboat
Tech Talk on Microservices at SquareboatSquareboat
 
Building Alexa Skills
Building Alexa SkillsBuilding Alexa Skills
Building Alexa SkillsSquareboat
 
Making Products to get users “Hooked”
Making Products to get users “Hooked”Making Products to get users “Hooked”
Making Products to get users “Hooked”Squareboat
 
Moving to Docker... Finally!
Moving to Docker... Finally!Moving to Docker... Finally!
Moving to Docker... Finally!Squareboat
 
Continuous Delivery process
Continuous Delivery processContinuous Delivery process
Continuous Delivery processSquareboat
 
HTML and CSS architecture for 2025
HTML and CSS architecture for 2025HTML and CSS architecture for 2025
HTML and CSS architecture for 2025Squareboat
 
The rise of Conversational User Interfaces
The rise of Conversational User Interfaces The rise of Conversational User Interfaces
The rise of Conversational User Interfaces Squareboat
 
Thinking of growth as a feature
Thinking of growth as a feature Thinking of growth as a feature
Thinking of growth as a feature Squareboat
 

Más de Squareboat (20)

Squareboat Deck
Squareboat DeckSquareboat Deck
Squareboat Deck
 
Squareboat Branding Proposal
Squareboat Branding ProposalSquareboat Branding Proposal
Squareboat Branding Proposal
 
Squareboat Product Foundation Process
Squareboat Product Foundation ProcessSquareboat Product Foundation Process
Squareboat Product Foundation Process
 
Squareboat Culture Deck
Squareboat Culture DeckSquareboat Culture Deck
Squareboat Culture Deck
 
Squareboat Design Portfolio
Squareboat Design PortfolioSquareboat Design Portfolio
Squareboat Design Portfolio
 
Squareboat Crew Deck
Squareboat Crew DeckSquareboat Crew Deck
Squareboat Crew Deck
 
High Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at SquareboatHigh Performance Mysql - Friday Tech Talks at Squareboat
High Performance Mysql - Friday Tech Talks at Squareboat
 
CTA - Call to Attention
CTA - Call to AttentionCTA - Call to Attention
CTA - Call to Attention
 
Tech talk on Tailwind CSS
Tech talk on Tailwind CSSTech talk on Tailwind CSS
Tech talk on Tailwind CSS
 
What’s New in Apple World - WWDC19
What’s New in Apple World - WWDC19What’s New in Apple World - WWDC19
What’s New in Apple World - WWDC19
 
Tech Talk on Microservices at Squareboat
Tech Talk on Microservices at SquareboatTech Talk on Microservices at Squareboat
Tech Talk on Microservices at Squareboat
 
Building Alexa Skills
Building Alexa SkillsBuilding Alexa Skills
Building Alexa Skills
 
Making Products to get users “Hooked”
Making Products to get users “Hooked”Making Products to get users “Hooked”
Making Products to get users “Hooked”
 
Moving to Docker... Finally!
Moving to Docker... Finally!Moving to Docker... Finally!
Moving to Docker... Finally!
 
Color Theory
Color TheoryColor Theory
Color Theory
 
Continuous Delivery process
Continuous Delivery processContinuous Delivery process
Continuous Delivery process
 
HTML and CSS architecture for 2025
HTML and CSS architecture for 2025HTML and CSS architecture for 2025
HTML and CSS architecture for 2025
 
Vue JS
Vue JSVue JS
Vue JS
 
The rise of Conversational User Interfaces
The rise of Conversational User Interfaces The rise of Conversational User Interfaces
The rise of Conversational User Interfaces
 
Thinking of growth as a feature
Thinking of growth as a feature Thinking of growth as a feature
Thinking of growth as a feature
 

Último

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Último (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

What’s new in Kotlin?

  • 2. Overview ● Kotlin is a new programming language from JetBrains ● First appeared in 2011, stable release 1.0 in Feb, 2016 ● “Statically typed programming language” ● Procedural as well as Functional Programming both ● Google announced official support for Kotlin on Android at Google I/O, 2017
  • 3. Benefits ● Kotlin compiles to JVM bytecode or JavaScript ● Kotlin programs can use all existing Java Frameworks and Libraries ● Kotlin can be learned easily ● Automatic conversion of Java to Kotlin with Android Studio ● Kotlin’s null-safety is great
  • 5. Extension Functions fun String.removeSpaces() { … } // call to extension function “Hello, I am Vipul Asri”.removeSpaces() // output “Hello,IamVipulAsri”
  • 6. Inter-operable With Java Java code can be used inside Kotlin code and vice-versa. class Person { String name = “Person Nath” public String getNameWithoutSpace() { return name.removeSpaces(); } }
  • 7. Synthetic Extension( bye bye to findViewById() ) Java class MainActivity extends AppCompatActivity{ TextView studentName; @Override protected void onCreate(Bundle savedInstanceState) { studentName = findViewById(R.id.studentName); studentName.setText("Harshit Dwivedi"); } } Kotlin import kotlinx.android.synthetic.main.activity_main.* class KotlinActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { studentName.text = "Harshit" //That's it! } }
  • 8. NPE Safety var name_1: String = "abc" name_1 = null // try to assign null, won’t compile. // To allow nulls, we declare a variable as nullable string var name_2: String? = "abc" name_2 = null // no compilation error. val len = name_1.length // there will be no NPE val len = name_2.length // error: variable 'name_2' can be null
  • 9. NPE Safety 1. Checking for null in conditions val len = if (name_2 != null) name_2.length else -1 2. Safe Calls (with ?.) name_2?.length // name_2.length if name_2 is not null, and null otherwise 3. The !! Operator (for NPE Lovers) - not-null assertion operator (!!) val l = b!!.length // (!!) converts any value to a non-null type // and throws an exception if the value is null
  • 10. Coroutines (experimental) ● Threads can easily eat up almost a megabyte of memory. In this context, we can call coroutines (as per the documentation) as "lightweight" threads. ● A coroutine is sitting on an actual thread pool, which is used for background execution. ● It only uses the resources when it needs it.
  • 11. launch{} val job = launch { val userString = fetchUserString("1") val user = deserializeUser(userString) log(user.name) } The wrapped code is dispatched to a background thread, and the function itself returns a Job instance, which can be used in other coroutines to control the execution.
  • 12. async{} val user = async { val userString = fetchUserString("1") val user = deserializeUser(userString) user }.await() The async function returns a Defered<T> instance, and calling await() on it you can get the actual result of the computation.
  • 15. Type Declaration Java int a = 1; String s = “abc”; boolean b; Kotlin val a: Int = 1 val s: String = “abc” val b: Boolean
  • 16. Type Inference Java int a = 1; String s = “abc”; boolean b; Kotlin val a = 1 val s = “abc” val b: Boolean
  • 17. Object Declaration - No ‘new’ Java Car car = new Car(); Kotlin val car = Car()
  • 18. String templates Java String s = String.format(“%s has %d apples, name, count); Kotlin val s = “$name has $count apples”
  • 19. Functions Java String getName(Person person) { return person.getName(); } Kotlin fun getName(person: Person): String { return person.name }
  • 20. Expressions body Java int sum(int a , int b) { return a+b; } Kotlin val sum(a: Int , b:Int) = a+b
  • 21. ‘When’ Expression Java switch(x) { case 1: log.info("x == 1"); break; case 2: log.info("x == 2"); break; default: log.info("x is neither 1 nor 2"); } Kotlin when (x) { in 0,1 -> print("x is too low") in 2..10 -> print("x is in range") !in 10..20 -> print("x outside range") parseInt(s) -> print("s encodes x") is Program -> print("It's a program!") else -> print("None of the above") }
  • 22. Ranges Java IntStream.rangeClosed(1, 5) .forEach(x -> ...); Kotlin for (x in 1..5) { ... }
  • 23. Data Classes Java class Address { final String city; Address(String n) { city = n; } String getCity() { return city; } void setCity(String n) { city = n; } int equals() { ... } hashCode() { ... } toString() { ... } copy() { ... } } Kotlin data class Address(var city:String, var country:Country)
  • 24. Kotlin 1.2 Sharing Code between Platforms
  • 25. ● JavaScript target, allowing you to compile Kotlin code to JS and to run it in your browser ● Reuse code between the JVM and JavaScript ● Business logic of your application once, and reuse it across all tiers of your application – the backend, the browser frontend and the Android mobile app
  • 26.