SlideShare a Scribd company logo
Kotlin for Java Developers
what every java developer should know about kotlin
Today I would like to share with you
● Why I care about Kotlin?
● 20 features I love
● 10 features you need to be aware of
● Ecosystem
Next JVM language?
● Statically typed programming language for multi platform applications
○ concise
○ safe
○ interoperable with Java
○ built together with tooling support
○ open source under Apache 2.0 license
● Version 1.0 released in 2015, current version 1.1.50 (September 2017)
● Google announced first-class support for Kotlin on Android
● Pivotal introduced Kotlin support in Spring Framework 5.0
● Easy to learn if you know Java
Kotlin basics
Features I love
Extension functions and properties
Data classes
● equals() / hashCode() pair
● toString() “Account[email=test]”
● componentN() functions in their order
of declaration
● copy() function
String templates
Null safety
● Types defines nullability
○ Platform types
● Safe calls
● Elvis operator
● !!. operator
● Safe casts
when
Operator overloading
● +, -, *, /, %, ..
○ a + b -> a.plus(b)
○ a..b -> a.rangeTo(b)
● in, !in
○ a.contains(b)
● Indexed access []
○ a[i] -> a.get(i)
○ a[i] = b -> a.set(i, b)
● Invoke
○ a(i, j) -> a.invoke(i, j)
● a == b
○ a?.equals(b) ?: (b === null)
● a > b, a < b, a >= b, a <= b -> a.compareTo(b)
Operator overloading (1)
Default and named parameters
Smart casts
Destructuring objects
● underscore for unused
variables (1.1)
● destructuring in lambdas
(1.1)
Lambda and closures
Expressions and statements
● if and when are expressions, not statements
○ val length = if (a is String) a.length else -1
○ val action = when (test) {
in 0..5 -> OPEN
else -> CLOSE
}
● assignment is a statement, not an expression
○ if (a = b) does not compile
○ while ((line = bufferedReader.readLine()) != null) does not compile
Packages and source code structure
● packages
● import allows to import classes, functions, *
● type aliases
● multiple classes in one file
● arbitrary file names
● arbitrary directory structure
● visibility modifiers: private, protected, internal, public
Other languages have all these features
● Null safety
● No checked exceptions
● Extension functions
● Function types and lambdas
● Default and named parameters
● Properties
● Operator overloading
● Smart casts
● Data classes
● Immutable collections
● Enhanced switch-case
● String templates
● Ranges
● Infix notation
● Inline functions
● Coroutines (async/await)
● Great standard library
● Sealed classes
● Delegated and lazy properties
● Class delegation
● Singletons
● Nested functions
● Object decomposition
● Top-level functions
● Reified generics
● Raw strings
● 100% interoperable with Java 6
● And more...
Compile and run with Java code
● you can mix Java and Kotlin code in one project
● experiment with new language without breaking or rewriting the whole
application
● small memory footprint of the Kotlin standard library
Understand decisions
What you need to know
● final by default and bytecode generation
● platform types and nullability
● no primitives, no implicit widening conversions for numbers
● standard library
Final by default and bytecode generation
● all classes, methods are final by default
○ tedious opening via ‘open’ keyword
○ interference with AOP (CGLIB), workarounds as compiler plugins ‘kotlin-spring’, ‘all-open’
● ‘override’ is a required keyword, not an annotation
● designing for inheritance
● kotlinc generates Java 6 or Java 8 bytecode
● on JVM lambdas does not use ‘invokedynamic’
● Kotlin Bytecode Generation and Runtime Performance
Platform types and nullability (!)
● any reference in Java may be null
● types of Java declarations are called platform types
● can be assigned to nullable or non-null type
● compiler, tools refers to them using as T! which means T ot T?
● nullability annotations (JSR-305, Android, Lombok, JetBrains, Eclipse)
Standard library
● kotlin-runtime and kotlin-stdlib -> kotlin-stdlib
○ < 1MB jar (JVM)
● Kotlin classes and extension functions to Java classes
○ kotlin
○ kotlin.collections
○ kotlin.comparisons
○ kotlin.concurrent
○ kotlin.io
○ kotlin.streams
○ kotlin.text
● kotlin.js
Platforms and tooling
Platforms and tooling
● JVM
a. Java 6 and 8
● Android
● JavaScript (ES5.1)
a. compatible with module systems like AMD, CommonJS
● native (LLVM)
a. LLVM is used to compile Kotlin into native code
b. technology preview for iOS, linux, MAC, (windows in the work)
● IntelliJ IDEA (Java to Kotlin converter), Eclipse
● Gradle, Maven, Ant
Where to start?
● Try online https://try.kotlinlang.org/
● Kotlin is Awesome! https://kotlin.link/
What will be your next JVM
language?
https://en.wikipedia.org/wiki/List_of_JVM_languages

More Related Content

PDF
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
PDF
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
PDF
TDC2016SP - Groovy como você nunca viu
tdc-globalcode
 
PPTX
Intro to Kotlin Minia GDG DevFest 2017
Shady Selim
 
PDF
OOPS Advanced
Madhavan Malolan
 
PPTX
Intro to kotlin
Tomislav Homan
 
PDF
Lightning talk: Kotlin
Evolve
 
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
TDC2016SP - Groovy como você nunca viu
tdc-globalcode
 
Intro to Kotlin Minia GDG DevFest 2017
Shady Selim
 
OOPS Advanced
Madhavan Malolan
 
Intro to kotlin
Tomislav Homan
 
Lightning talk: Kotlin
Evolve
 

What's hot (20)

PDF
Object Oriented Programming : Part 2
Madhavan Malolan
 
PDF
Ruxmon.2013-08.-.CodeBro!
Christophe Alladoum
 
PDF
Clang Analyzer Tool Review
Doug Schuster
 
ODP
Phpactor and VIM
dantleech
 
PDF
Introduction to Kotlin JVM language
Andrius Klimavicius
 
PDF
Getting Started with PHP Extensions
MichaelBrunoLochemem
 
PDF
Kotlin & Arrow the functional way
Thoughtworks
 
PDF
A Shallow Survey of Alternative Languages on the JVM
Charles Anderson
 
PPTX
Modern Programming Languages - An overview
Ayman Mahfouz
 
PPTX
Android with kotlin course
Abdul Rahman Masri Attal
 
PDF
Kotlin & arrow: the functional way
nluaces
 
PPTX
Kotlin - A Programming Language
Mobio Solutions
 
PPTX
Coding in kotlin
Debmalya Jash
 
PDF
Java 8 Lambda
François Sarradin
 
PDF
Clojure presentation
Karthik Raghunahtan
 
KEY
Test-driven language development
lennartkats
 
PPTX
TypeScript intro
Ats Uiboupin
 
PDF
The Spoofax Language Workbench (SPLASH 2010)
lennartkats
 
PPTX
.NET compiler platform codename Roslyn
Piotr Benetkiewicz
 
PDF
Lock-free algorithms for Kotlin Coroutines
Roman Elizarov
 
Object Oriented Programming : Part 2
Madhavan Malolan
 
Ruxmon.2013-08.-.CodeBro!
Christophe Alladoum
 
Clang Analyzer Tool Review
Doug Schuster
 
Phpactor and VIM
dantleech
 
Introduction to Kotlin JVM language
Andrius Klimavicius
 
Getting Started with PHP Extensions
MichaelBrunoLochemem
 
Kotlin & Arrow the functional way
Thoughtworks
 
A Shallow Survey of Alternative Languages on the JVM
Charles Anderson
 
Modern Programming Languages - An overview
Ayman Mahfouz
 
Android with kotlin course
Abdul Rahman Masri Attal
 
Kotlin & arrow: the functional way
nluaces
 
Kotlin - A Programming Language
Mobio Solutions
 
Coding in kotlin
Debmalya Jash
 
Java 8 Lambda
François Sarradin
 
Clojure presentation
Karthik Raghunahtan
 
Test-driven language development
lennartkats
 
TypeScript intro
Ats Uiboupin
 
The Spoofax Language Workbench (SPLASH 2010)
lennartkats
 
.NET compiler platform codename Roslyn
Piotr Benetkiewicz
 
Lock-free algorithms for Kotlin Coroutines
Roman Elizarov
 
Ad

Similar to JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński) (20)

PPTX
Kotlin
Sudhanshu Vohra
 
PPTX
Kotlin
Ravi Pawar
 
PDF
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
PPSX
Kotlin Language powerpoint show file
Saurabh Tripathi
 
PDF
A Brief Overview of Kotlin
Sevil Güler
 
PDF
Kotlin from-scratch
Franco Lombardo
 
PDF
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
Leonardo Zanivan
 
PDF
A Review Paper on Kotlin Programming Language
ijtsrd
 
PDF
Introduction to kotlin for Java Developer
troubledkumi
 
PDF
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
What’s new in Kotlin?
Squareboat
 
PPTX
Introduction to Kotlin
T.M. Ishrak Hussain
 
PDF
Kotlin: a better Java
Nils Breunese
 
PPTX
Kotlin Overview
Ekta Raj
 
PDF
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
PDF
Why You Should Go with Kotlin for Android App Development.pdf
RipenApps
 
PPTX
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Eamonn Boyle
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PDF
Kotlin vs Java: Choosing The Right Language
FredReynolds2
 
PPTX
The-Future-of-Kotlin-What-Developers-Need-to-Know.pptx
JHK Infotech
 
Kotlin
Ravi Pawar
 
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
Kotlin Language powerpoint show file
Saurabh Tripathi
 
A Brief Overview of Kotlin
Sevil Güler
 
Kotlin from-scratch
Franco Lombardo
 
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
Leonardo Zanivan
 
A Review Paper on Kotlin Programming Language
ijtsrd
 
Introduction to kotlin for Java Developer
troubledkumi
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
What’s new in Kotlin?
Squareboat
 
Introduction to Kotlin
T.M. Ishrak Hussain
 
Kotlin: a better Java
Nils Breunese
 
Kotlin Overview
Ekta Raj
 
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Why You Should Go with Kotlin for Android App Development.pdf
RipenApps
 
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Eamonn Boyle
 
A quick and fast intro to Kotlin
XPeppers
 
Kotlin vs Java: Choosing The Right Language
FredReynolds2
 
The-Future-of-Kotlin-What-Developers-Need-to-Know.pptx
JHK Infotech
 
Ad

Recently uploaded (20)

PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
This slide provides an overview Technology
mineshkharadi333
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)

  • 1. Kotlin for Java Developers what every java developer should know about kotlin
  • 2. Today I would like to share with you ● Why I care about Kotlin? ● 20 features I love ● 10 features you need to be aware of ● Ecosystem
  • 3. Next JVM language? ● Statically typed programming language for multi platform applications ○ concise ○ safe ○ interoperable with Java ○ built together with tooling support ○ open source under Apache 2.0 license ● Version 1.0 released in 2015, current version 1.1.50 (September 2017) ● Google announced first-class support for Kotlin on Android ● Pivotal introduced Kotlin support in Spring Framework 5.0 ● Easy to learn if you know Java
  • 7. Data classes ● equals() / hashCode() pair ● toString() “Account[email=test]” ● componentN() functions in their order of declaration ● copy() function
  • 9. Null safety ● Types defines nullability ○ Platform types ● Safe calls ● Elvis operator ● !!. operator ● Safe casts
  • 10. when
  • 11. Operator overloading ● +, -, *, /, %, .. ○ a + b -> a.plus(b) ○ a..b -> a.rangeTo(b) ● in, !in ○ a.contains(b) ● Indexed access [] ○ a[i] -> a.get(i) ○ a[i] = b -> a.set(i, b) ● Invoke ○ a(i, j) -> a.invoke(i, j) ● a == b ○ a?.equals(b) ?: (b === null) ● a > b, a < b, a >= b, a <= b -> a.compareTo(b)
  • 13. Default and named parameters
  • 15. Destructuring objects ● underscore for unused variables (1.1) ● destructuring in lambdas (1.1)
  • 17. Expressions and statements ● if and when are expressions, not statements ○ val length = if (a is String) a.length else -1 ○ val action = when (test) { in 0..5 -> OPEN else -> CLOSE } ● assignment is a statement, not an expression ○ if (a = b) does not compile ○ while ((line = bufferedReader.readLine()) != null) does not compile
  • 18. Packages and source code structure ● packages ● import allows to import classes, functions, * ● type aliases ● multiple classes in one file ● arbitrary file names ● arbitrary directory structure ● visibility modifiers: private, protected, internal, public
  • 19. Other languages have all these features ● Null safety ● No checked exceptions ● Extension functions ● Function types and lambdas ● Default and named parameters ● Properties ● Operator overloading ● Smart casts ● Data classes ● Immutable collections ● Enhanced switch-case ● String templates ● Ranges ● Infix notation ● Inline functions ● Coroutines (async/await) ● Great standard library ● Sealed classes ● Delegated and lazy properties ● Class delegation ● Singletons ● Nested functions ● Object decomposition ● Top-level functions ● Reified generics ● Raw strings ● 100% interoperable with Java 6 ● And more...
  • 20. Compile and run with Java code ● you can mix Java and Kotlin code in one project ● experiment with new language without breaking or rewriting the whole application ● small memory footprint of the Kotlin standard library
  • 22. What you need to know ● final by default and bytecode generation ● platform types and nullability ● no primitives, no implicit widening conversions for numbers ● standard library
  • 23. Final by default and bytecode generation ● all classes, methods are final by default ○ tedious opening via ‘open’ keyword ○ interference with AOP (CGLIB), workarounds as compiler plugins ‘kotlin-spring’, ‘all-open’ ● ‘override’ is a required keyword, not an annotation ● designing for inheritance ● kotlinc generates Java 6 or Java 8 bytecode ● on JVM lambdas does not use ‘invokedynamic’ ● Kotlin Bytecode Generation and Runtime Performance
  • 24. Platform types and nullability (!) ● any reference in Java may be null ● types of Java declarations are called platform types ● can be assigned to nullable or non-null type ● compiler, tools refers to them using as T! which means T ot T? ● nullability annotations (JSR-305, Android, Lombok, JetBrains, Eclipse)
  • 25. Standard library ● kotlin-runtime and kotlin-stdlib -> kotlin-stdlib ○ < 1MB jar (JVM) ● Kotlin classes and extension functions to Java classes ○ kotlin ○ kotlin.collections ○ kotlin.comparisons ○ kotlin.concurrent ○ kotlin.io ○ kotlin.streams ○ kotlin.text ● kotlin.js
  • 27. Platforms and tooling ● JVM a. Java 6 and 8 ● Android ● JavaScript (ES5.1) a. compatible with module systems like AMD, CommonJS ● native (LLVM) a. LLVM is used to compile Kotlin into native code b. technology preview for iOS, linux, MAC, (windows in the work) ● IntelliJ IDEA (Java to Kotlin converter), Eclipse ● Gradle, Maven, Ant
  • 28. Where to start? ● Try online https://try.kotlinlang.org/ ● Kotlin is Awesome! https://kotlin.link/
  • 29. What will be your next JVM language? https://en.wikipedia.org/wiki/List_of_JVM_languages