SlideShare a Scribd company logo
Is there Kotlin after Java 8
Ivan Turčinović & Igor Buzatović
What is Kotlin?General
2
Statically typed, JVM-targeted language
Design principles: Industrial use, tooling, safety
Compiles to JVM byte code and JavaScript
Runtime size 800K
Current status, plans, release dateGeneral
No release date, no spec yet
Roadmap
M1 → M2 → … → Beta → Jetbrains project → V1.0
Latest milestone → M7
3
Some frameworks/libraries already appeared
Kara Web Framework – Statically typed HTML/CSS
Spek – Specification/test framework
Kannotator – Infer annotations from bytecode
KotlinPrimavera - Kotlin libraries to Spring projects
Java strikes back with Java 8
Advantages over Java 7 are overwhelming
Java 8 introduced
Lambdas
General
4
Lambdas
Null safety (“Optional” class)
Default methods
Streams API
New Date & Time API
But even with Java 8 Kotlin still...
Is more elegant, concise and safe
General
5
Has more cool stuff
Basic syntax and rulesMore elegant?
Functions - definition in
package or in class
Immutable/mutable
variables
No „new” keyword
Type inference
6
Type inference
No checked exceptions
No primitive types
No static members
More elegant? Basic syntax and rules cont’d
7
Primary constructors
No fields, just properties
Bean style classes easy to declare
By default, all classes are final
More elegant?
Null safety
• Null reference – Billion dollar mistake
• Kotlin is designed in a way that aims to
eliminate NPE from our code
8
GenericsMore elegant?
Not co-variant by default, reason?
Wildcards, use-site variance
Co-variance price, producers
Contra-variance, consumers
Bloch: "PECS: Producer extend,
Consumer super“
Java
9
Declaration-site variance
out / in generics modifiers
Supports use-site variance also
No wildcard syntax, out / in used
Kotlin
Java survey: 39% of wildcards usage can be replaced by declaration-site variance
Default arguments, named argumentsMore cool stuff
Default argument values can
be defined
Arguments with default
values are optional
No more need for function
overloading (almost)
10
overloading (almost)
Kotlin classes can have only
one constructor
Arguments can be called by
name
When passing arguments by
name ordering doesn’t
matter
RangesMore cool stuff
Simpler “is it in range” check
Can be used for any type
that implements
Comparable
“both ends“ included
“..” operator is translated to
“rangeTo” function
11
“rangeTo” function
“rangeTo” function is
implemented as extension
function on Comparable
Numerical ranges can be
iterated over
In both directions and in
arbitrary steps
Pattern matchingMore cool stuff
Java’s instaceof not very practical
No !instanceof
Meet Kotlin’s "is“
12
"is" negation "!is“
Automatic type cast when “is”
evaluates true inside if / when
blocks
Data classesMore cool stuff
Classes very easy to declare
Data annotation changes
13
Output
javacro.User@41a7d9e7
1101519335
1926426205
false
Data annotation changes
behavior of hashCode,
equals, toString functions
Default implementation uses
all properties
Off course we can override
Data classesMore cool stuff
Classes very easy to declare
Data annotation changes
14
Output
User(firstName=John,lastName=Doe)
71819599
71819599
true
Data annotation changes
behavior of hashCode,
equals, toString functions
Default implementation uses
all properties
Off course we can override
Operator overloadingMore cool stuff
Operators are translated to
corresponding functions
Operator set is fixed
Operator overloading is achieved by
overriding corresponding functions of
specific class
15
specific class
By adding extension functions we can
enable certain operator for classes that
don’t support it originally
On our own classes we can enable
certain operator by implementing
corresponding functions
Extension functionsMore cool stuff
What to do if we want to add features
to existing classes
Java: extending or utility classes
Kotlin: add functions to existing
classes without changing their code
Example: implement BigDecimal +
16
Example: implement BigDecimal +
operator
How does it work “behind the scene”?
Extension functionsMore cool stuff
What to do if we want to add features
to existing classes
Java: extending or utility classes
Kotlin: add functions to existing
classes without changing their code
Example: implement BigDecimal +
17
Example: implement BigDecimal +
operator
How does it work “behind the scene”?
Kotlin collectionsMore cool stuff
18
Read-only traits on top, co-variant
Extended by mutable traits
Implemented by JDK classes (compile time modifications)
Read-only traits do not guarantee immutability
Top level package functions for instantiating collections:
Read-only: setOf, listOf, mapOf
Mutable: hashSetOff, arrayListOf, hashMapOf
Type-safe Groovy-style buildersMore cool stuff
19
For generating tree-like structures (UI layouts, 3D scene graphs)
Tree-like syntax – better insight in what is being generated
Functions create, initialize and return builder specific objects
Better then xml: no scheme required, type safe, interoperable with other code
Type-safe Groovy-style buildersMore cool stuff
Objects initialized using
function literal argument
Extension function literal
allows referencing to object
enclosing element
20
enclosing element
Kara web framework using it
for HTML layouts, CSS
Android apps, XML layouts
Thank You!
21
Thank You!

More Related Content

PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
PPT
Java, Ruby & Rails
ODP
Unit Testing and Coverage for AngularJS
PDF
Gatling @ Scala.Io 2013
PPTX
Java 7 Whats New(), Whats Next() from Oredev
ODP
Open Source Compiler Construction for the JVM
PDF
Jan Stepien - Introducing structure in Clojure - Codemotion Milan 2017
PDF
Runmodes and Configs for Fun and Profit
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Java, Ruby & Rails
Unit Testing and Coverage for AngularJS
Gatling @ Scala.Io 2013
Java 7 Whats New(), Whats Next() from Oredev
Open Source Compiler Construction for the JVM
Jan Stepien - Introducing structure in Clojure - Codemotion Milan 2017
Runmodes and Configs for Fun and Profit

What's hot (19)

ODP
Gatling
PPTX
Java 8 parallel stream
PPT
ODP
An Introduction To Java Profiling
PPTX
Java7 - Top 10 Features
PPTX
Hybrid Applications
PPTX
JAVA 8 Parallel Stream
PDF
Smart Migration to JDK 8
PDF
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
PDF
Lagergren jvmls-2013-final
PPTX
Graal in GraalVM - A New JIT Compiler
PPTX
Java 8 concurrency abstractions
PPTX
Nashorn: JavaScript that doesn’t suck (ILJUG)
PDF
Survive JavaScript - Strategies and Tricks
PDF
PDF
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
PDF
Quick tour to front end unit testing using jasmine
PDF
Why and how Pricing Assistant migrated from Celery to RQ - Paris.py #2
PDF
rx-java-presentation
Gatling
Java 8 parallel stream
An Introduction To Java Profiling
Java7 - Top 10 Features
Hybrid Applications
JAVA 8 Parallel Stream
Smart Migration to JDK 8
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
Lagergren jvmls-2013-final
Graal in GraalVM - A New JIT Compiler
Java 8 concurrency abstractions
Nashorn: JavaScript that doesn’t suck (ILJUG)
Survive JavaScript - Strategies and Tricks
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
Quick tour to front end unit testing using jasmine
Why and how Pricing Assistant migrated from Celery to RQ - Paris.py #2
rx-java-presentation
Ad

Viewers also liked (20)

PPT
The Kotlin Programming Language
PDF
Kotlin Bytecode Generation and Runtime Performance
PDF
JavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan Raguž
PDF
JavaCro'14 - Vaadin scalability myth – Gordan Ivanović
PDF
JavaCro'14 - Automatic database migrations – Marko Elezović
PDF
PDF
JavaCro'14 - How to handle large amounts of data in real time using a cloud e...
PDF
JavaCro'14 - Gatling – weapon in ranks of performance testing – Andrija Kranjec
PDF
JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...
PDF
JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...
PDF
JavaCro'14 - Is there a single “correct” web architecture for business apps –...
PDF
JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...
PDF
JavaCro'14 - Securing web applications with Spring Security 3 – Fernando Redo...
PDF
JavaCro'14 - Sustainability of business performance and best practices – Zlat...
PDF
JavaCro'14 - MEAN Stack – How & When – Nenad Pećanac
PDF
JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer
PDF
JavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan Kljajin
PDF
JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...
PDF
JavaCro'14 - Developing Google Chromecast applications on Android – Branimir ...
PDF
JavaCro'14 - Profile any environment with Java Flight Recorder – Johan Janssen
The Kotlin Programming Language
Kotlin Bytecode Generation and Runtime Performance
JavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan Raguž
JavaCro'14 - Vaadin scalability myth – Gordan Ivanović
JavaCro'14 - Automatic database migrations – Marko Elezović
JavaCro'14 - How to handle large amounts of data in real time using a cloud e...
JavaCro'14 - Gatling – weapon in ranks of performance testing – Andrija Kranjec
JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...
JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...
JavaCro'14 - Is there a single “correct” web architecture for business apps –...
JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...
JavaCro'14 - Securing web applications with Spring Security 3 – Fernando Redo...
JavaCro'14 - Sustainability of business performance and best practices – Zlat...
JavaCro'14 - MEAN Stack – How & When – Nenad Pećanac
JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer
JavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan Kljajin
JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...
JavaCro'14 - Developing Google Chromecast applications on Android – Branimir ...
JavaCro'14 - Profile any environment with Java Flight Recorder – Johan Janssen
Ad

Similar to JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović (20)

PDF
Java To Kotlin A Refactoring Guidebook 1st Edition Duncan Mcgregor
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
PPTX
Why kotlininandroid
PDF
Kotlin what_you_need_to_know-converted event 4 with nigerians
PPTX
Intro to kotlin 2018
PDF
A quick and fast intro to Kotlin
PDF
Kotlin for Android Developers - 1
PDF
Be More Productive with Kotlin
PDF
Introduction to kotlin for Java Developer
PDF
Intro to Kotlin
PDF
kotlin.pdf
PPTX
Kotlin presentation
PDF
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
PPTX
Introduction to Kotlin Language and its application to Android platform
PDF
Kotlin in Action, Second Edition (MEAP V09) Svetlana Isakova
PDF
Introduction to Kotlin - Android KTX
PDF
Having Fun with Kotlin Android - DILo Surabaya
PDF
From Java to Kotlin
PDF
Android 101 - Kotlin ( Future of Android Development)
PPTX
Hello kotlin | An Event by DSC Unideb
Java To Kotlin A Refactoring Guidebook 1st Edition Duncan Mcgregor
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
Why kotlininandroid
Kotlin what_you_need_to_know-converted event 4 with nigerians
Intro to kotlin 2018
A quick and fast intro to Kotlin
Kotlin for Android Developers - 1
Be More Productive with Kotlin
Introduction to kotlin for Java Developer
Intro to Kotlin
kotlin.pdf
Kotlin presentation
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
Introduction to Kotlin Language and its application to Android platform
Kotlin in Action, Second Edition (MEAP V09) Svetlana Isakova
Introduction to Kotlin - Android KTX
Having Fun with Kotlin Android - DILo Surabaya
From Java to Kotlin
Android 101 - Kotlin ( Future of Android Development)
Hello kotlin | An Event by DSC Unideb

More from HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association (20)

PDF
Java cro'21 the best tools for java developers in 2021 - hujak
PDF
JavaCro'21 - Java is Here To Stay - HUJAK Keynote
PDF
Javantura v7 - Behaviour Driven Development with Cucumber - Ivan Lozić
PPTX
Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...
PPTX
Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...
PDF
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
PDF
Javantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander Radovan
PDF
Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...
PPTX
Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...
PDF
Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...
PDF
Javantura v6 - When remote work really works - the secrets behind successful ...
PDF
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
PDF
Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...
PDF
Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...
PPTX
Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...
PDF
Javantura v6 - How can you improve the quality of your application - Ioannis ...
PDF
Javantura v6 - Automation of web apps testing - Hrvoje Ruhek
PDF
Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...
PDF
Javantura v6 - Building IoT Middleware with Microservices - Mario Kusek
PDF
Javantura v6 - JDK 11 & JDK 12 - Dalibor Topic
Java cro'21 the best tools for java developers in 2021 - hujak
JavaCro'21 - Java is Here To Stay - HUJAK Keynote
Javantura v7 - Behaviour Driven Development with Cucumber - Ivan Lozić
Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...
Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
Javantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander Radovan
Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...
Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...
Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...
Javantura v6 - When remote work really works - the secrets behind successful ...
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...
Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...
Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...
Javantura v6 - How can you improve the quality of your application - Ioannis ...
Javantura v6 - Automation of web apps testing - Hrvoje Ruhek
Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...
Javantura v6 - Building IoT Middleware with Microservices - Mario Kusek
Javantura v6 - JDK 11 & JDK 12 - Dalibor Topic

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?

JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović

  • 1. Is there Kotlin after Java 8 Ivan Turčinović & Igor Buzatović
  • 2. What is Kotlin?General 2 Statically typed, JVM-targeted language Design principles: Industrial use, tooling, safety Compiles to JVM byte code and JavaScript Runtime size 800K
  • 3. Current status, plans, release dateGeneral No release date, no spec yet Roadmap M1 → M2 → … → Beta → Jetbrains project → V1.0 Latest milestone → M7 3 Some frameworks/libraries already appeared Kara Web Framework – Statically typed HTML/CSS Spek – Specification/test framework Kannotator – Infer annotations from bytecode KotlinPrimavera - Kotlin libraries to Spring projects
  • 4. Java strikes back with Java 8 Advantages over Java 7 are overwhelming Java 8 introduced Lambdas General 4 Lambdas Null safety (“Optional” class) Default methods Streams API New Date & Time API
  • 5. But even with Java 8 Kotlin still... Is more elegant, concise and safe General 5 Has more cool stuff
  • 6. Basic syntax and rulesMore elegant? Functions - definition in package or in class Immutable/mutable variables No „new” keyword Type inference 6 Type inference No checked exceptions No primitive types No static members
  • 7. More elegant? Basic syntax and rules cont’d 7 Primary constructors No fields, just properties Bean style classes easy to declare By default, all classes are final
  • 8. More elegant? Null safety • Null reference – Billion dollar mistake • Kotlin is designed in a way that aims to eliminate NPE from our code 8
  • 9. GenericsMore elegant? Not co-variant by default, reason? Wildcards, use-site variance Co-variance price, producers Contra-variance, consumers Bloch: "PECS: Producer extend, Consumer super“ Java 9 Declaration-site variance out / in generics modifiers Supports use-site variance also No wildcard syntax, out / in used Kotlin Java survey: 39% of wildcards usage can be replaced by declaration-site variance
  • 10. Default arguments, named argumentsMore cool stuff Default argument values can be defined Arguments with default values are optional No more need for function overloading (almost) 10 overloading (almost) Kotlin classes can have only one constructor Arguments can be called by name When passing arguments by name ordering doesn’t matter
  • 11. RangesMore cool stuff Simpler “is it in range” check Can be used for any type that implements Comparable “both ends“ included “..” operator is translated to “rangeTo” function 11 “rangeTo” function “rangeTo” function is implemented as extension function on Comparable Numerical ranges can be iterated over In both directions and in arbitrary steps
  • 12. Pattern matchingMore cool stuff Java’s instaceof not very practical No !instanceof Meet Kotlin’s "is“ 12 "is" negation "!is“ Automatic type cast when “is” evaluates true inside if / when blocks
  • 13. Data classesMore cool stuff Classes very easy to declare Data annotation changes 13 Output javacro.User@41a7d9e7 1101519335 1926426205 false Data annotation changes behavior of hashCode, equals, toString functions Default implementation uses all properties Off course we can override
  • 14. Data classesMore cool stuff Classes very easy to declare Data annotation changes 14 Output User(firstName=John,lastName=Doe) 71819599 71819599 true Data annotation changes behavior of hashCode, equals, toString functions Default implementation uses all properties Off course we can override
  • 15. Operator overloadingMore cool stuff Operators are translated to corresponding functions Operator set is fixed Operator overloading is achieved by overriding corresponding functions of specific class 15 specific class By adding extension functions we can enable certain operator for classes that don’t support it originally On our own classes we can enable certain operator by implementing corresponding functions
  • 16. Extension functionsMore cool stuff What to do if we want to add features to existing classes Java: extending or utility classes Kotlin: add functions to existing classes without changing their code Example: implement BigDecimal + 16 Example: implement BigDecimal + operator How does it work “behind the scene”?
  • 17. Extension functionsMore cool stuff What to do if we want to add features to existing classes Java: extending or utility classes Kotlin: add functions to existing classes without changing their code Example: implement BigDecimal + 17 Example: implement BigDecimal + operator How does it work “behind the scene”?
  • 18. Kotlin collectionsMore cool stuff 18 Read-only traits on top, co-variant Extended by mutable traits Implemented by JDK classes (compile time modifications) Read-only traits do not guarantee immutability Top level package functions for instantiating collections: Read-only: setOf, listOf, mapOf Mutable: hashSetOff, arrayListOf, hashMapOf
  • 19. Type-safe Groovy-style buildersMore cool stuff 19 For generating tree-like structures (UI layouts, 3D scene graphs) Tree-like syntax – better insight in what is being generated Functions create, initialize and return builder specific objects Better then xml: no scheme required, type safe, interoperable with other code
  • 20. Type-safe Groovy-style buildersMore cool stuff Objects initialized using function literal argument Extension function literal allows referencing to object enclosing element 20 enclosing element Kara web framework using it for HTML layouts, CSS Android apps, XML layouts