SlideShare a Scribd company logo
1 of 29
Download to read offline
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

What's hot

Clang Analyzer Tool Review
Clang Analyzer Tool ReviewClang Analyzer Tool Review
Clang Analyzer Tool Review
Doug Schuster
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
Charles Anderson
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
lennartkats
 

What's hot (20)

Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Clang Analyzer Tool Review
Clang Analyzer Tool ReviewClang Analyzer Tool Review
Clang Analyzer Tool Review
 
Phpactor and VIM
Phpactor and VIMPhpactor and VIM
Phpactor and VIM
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM language
 
Getting Started with PHP Extensions
Getting Started with PHP ExtensionsGetting Started with PHP Extensions
Getting Started with PHP Extensions
 
Kotlin & Arrow the functional way
Kotlin & Arrow the functional wayKotlin & Arrow the functional way
Kotlin & Arrow the functional way
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
 
Modern Programming Languages - An overview
Modern Programming Languages - An overviewModern Programming Languages - An overview
Modern Programming Languages - An overview
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
 
Kotlin & arrow: the functional way
Kotlin & arrow:  the functional wayKotlin & arrow:  the functional way
Kotlin & arrow: the functional way
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Clojure presentation
Clojure presentationClojure presentation
Clojure presentation
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)
 
.NET compiler platform codename Roslyn
.NET compiler platform codename Roslyn.NET compiler platform codename Roslyn
.NET compiler platform codename Roslyn
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 

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

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

Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Why Kotlin?
Why Kotlin?Why Kotlin?
Why Kotlin?
 
Kotlin Online Training.pdf
Kotlin Online Training.pdfKotlin Online Training.pdf
Kotlin Online Training.pdf
 
Kotlin tlv
Kotlin tlvKotlin tlv
Kotlin tlv
 
Understand What and Why Kotlin.pptx
Understand What and Why Kotlin.pptxUnderstand What and Why Kotlin.pptx
Understand What and Why Kotlin.pptx
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
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
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Python assignment help from professional programmers
Python assignment help from professional programmersPython assignment help from professional programmers
Python assignment help from professional programmers
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
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
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
 
Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?
 
Unit 1
Unit 1Unit 1
Unit 1
 
Quality Assurance in PostgreSQL
Quality Assurance in PostgreSQLQuality Assurance in PostgreSQL
Quality Assurance in PostgreSQL
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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