SlideShare a Scribd company logo
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!

More Related Content

What's hot

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
JAX London
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
Haim Yadid
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
Alexey Soshin
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
Kai 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 Development
Adam Magaña
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
Adit Lal
 
Java 7
Java 7Java 7
Java 7
Bipul Sinha
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
Jieyi Wu
 
Ejb3.1
Ejb3.1Ejb3.1
Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With Kotlin
Gaurav sharma
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
HDR1001
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015
Dierk König
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
rsebbe
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11
Åsa Pehrsson
 
CODEsign 2015
CODEsign 2015CODEsign 2015
CODEsign 2015
Max Kleiner
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
Iván López Martín
 

What's hot (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 to 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 - mRready
MobileAcademy
 
Боремся с 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 Android
Kurt Renzo Acosta
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
Mohamed 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 Surabaya
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
Arnaud Giuliani
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
DJ Rausch
 
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
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better Java
Nils Breunese
 
Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
Kurt Renzo Acosta
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
Alexey 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 development
Jayaprakash R
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
Speck&Tech
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
Magda 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 Kotlin
Luca 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
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
Abhijeet Dubey
 
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
 

Similar to 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
 

More from Squareboat

Squareboat Deck
Squareboat DeckSquareboat Deck
Squareboat Deck
Squareboat
 
Squareboat Branding Proposal
Squareboat Branding ProposalSquareboat Branding Proposal
Squareboat Branding Proposal
Squareboat
 
Squareboat Product Foundation Process
Squareboat Product Foundation ProcessSquareboat Product Foundation Process
Squareboat Product Foundation Process
Squareboat
 
Squareboat Culture Deck
Squareboat Culture DeckSquareboat Culture Deck
Squareboat Culture Deck
Squareboat
 
Squareboat Design Portfolio
Squareboat Design PortfolioSquareboat Design Portfolio
Squareboat Design Portfolio
Squareboat
 
Squareboat Crew Deck
Squareboat Crew DeckSquareboat Crew Deck
Squareboat Crew Deck
Squareboat
 
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
Squareboat
 
CTA - Call to Attention
CTA - Call to AttentionCTA - Call to Attention
CTA - Call to Attention
Squareboat
 
Tech talk on Tailwind CSS
Tech talk on Tailwind CSSTech talk on Tailwind CSS
Tech talk on Tailwind CSS
Squareboat
 
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
Squareboat
 
Tech Talk on Microservices at Squareboat
Tech Talk on Microservices at SquareboatTech Talk on Microservices at Squareboat
Tech Talk on Microservices at Squareboat
Squareboat
 
Building Alexa Skills
Building Alexa SkillsBuilding Alexa Skills
Building Alexa Skills
Squareboat
 
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
 
Color Theory
Color TheoryColor Theory
Color Theory
Squareboat
 
Continuous Delivery process
Continuous Delivery processContinuous Delivery process
Continuous Delivery process
Squareboat
 
HTML and CSS architecture for 2025
HTML and CSS architecture for 2025HTML and CSS architecture for 2025
HTML and CSS architecture for 2025
Squareboat
 
Vue JS
Vue JSVue JS
Vue JS
Squareboat
 
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
 

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

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 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.