SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
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!

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 

Dernier (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

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.