SlideShare a Scribd company logo
1 of 57
Download to read offline
@PaulienVanAlst#Devoxx #Kotlin
From Java to Kotlin
The adventures of a smooth migration
Paulien van Alst
Open Value
@PaulienVanAlst#Devoxx #Kotlin
Who am I?
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin
Developed by Jetbrains
Adopted by Google for Android
Development
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin
J V M
J S
M u l t i p l a t f o r m
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin
J V M
J S
M u l t i p l a t f o r m
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin
Expressiveness
Reuse
Interoperability
Safety
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
boardGameRepository.findAllByCategory(ADVENTURE)
.moreThanTwoPlayers()
.olderThanTenToPlay()
.meanPrice()
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
boardGameRepository.findAllByCategory(ADVENTURE)
.moreThanTwoPlayers()
.olderThanTenToPlay()
.meanPrice()
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
boardGameRepository.findAllByCategory(ADVENTURE)
.moreThanTwoPlayers()
.olderThanTenToPlay()
.meanPrice()
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
boardGameRepository.findAllByCategory(ADVENTURE)
.moreThanTwoPlayers()
.olderThanTenToPlay()
.meanPrice()
@PaulienVanAlst#Devoxx #Kotlin
My story with Kotlin
boardGameRepository.findAllByCategory(ADVENTURE).stream()
.filter(game -> game.getMinimalNumberOfPlayers() > 2)
.filter(game -> game.getMinimalAge() > 10)
.map(BoardGameEntity::getPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add);
boardGameRepository.findAllByCategory(ADVENTURE)
.moreThanTwoPlayers()
.olderThanTenToPlay()
.meanPrice()
@PaulienVanAlst#Devoxx #Kotlin
Pro’s to switch to Kotlin
Regular updates
Interoperability
Multiplatform
@PaulienVanAlst#Devoxx #Kotlin
Pro’s to switch to Kotlin
Null safety Immutability
@PaulienVanAlst#Devoxx #Kotlin
Pro’s to switch to Kotlin
Null safety Immutability
Operator overloading
@PaulienVanAlst#Devoxx #Kotlin
Pro’s to switch to Kotlin
Null safety Immutability
Operator overloading
Extension functions
@PaulienVanAlst#Devoxx #Kotlin
Pro’s to switch to Kotlin
Null safety Immutability
Operator overloading
Extension functions
Coroutines
@PaulienVanAlst#Devoxx #Kotlin
What to keep in mind
Interoperability
Idioms
Magic problem solver
@PaulienVanAlst#Devoxx #Kotlin
What to keep in mind
Interoperability
Idioms
Magic problem solver
@PaulienVanAlst#Devoxx #Kotlin
Warning!
DO this at home
or
In a POC
@PaulienVanAlst#Devoxx #Kotlin
Let’s start!
Rates 6 8
Games above … 8 9 9,5
@PaulienVanAlst#Devoxx #Kotlin
Let’s start!
Spring boot 2
In memory database
UT’s and IT’s
@PaulienVanAlst#Devoxx #Kotlin
Let’s start!
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version</version>
<scope>test</scope>
</dependency>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version</version>
<scope>test</scope>
</dependency>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration><jvmTarget>1.8</jvmTarget></configuration>
<executions>
<execution><id> compile </id> </execution>
<execution><id> test-compile </id> </execution>
</executions>
</plugin>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration><jvmTarget>1.8</jvmTarget></configuration>
<executions>
<execution><id> compile </id> </execution>
<execution><id> test-compile </id> </execution>
</executions>
</plugin>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration><jvmTarget>1.8</jvmTarget></configuration>
<executions>
<execution><id> compile </id> </execution>
<execution><id> test-compile </id> </execution>
</executions>
</plugin>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration><jvmTarget>1.8</jvmTarget></configuration>
<executions>
<execution><id> compile </id> </execution>
<execution><id> test-compile </id> </execution>
</executions>
</plugin>
Set-up dependencies
@PaulienVanAlst#Devoxx #Kotlin
Set-up dependencies
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
Migrate PoJo’s
@Value
public class BoardGame {
private final String name;
private final Category category;
private final AgeRange ageRange;
private final NumberOfPlayers numberOfPlayers;
private final Rating rating;
}
@PaulienVanAlst#Devoxx #Kotlin
Migrate PoJo’s
@Value
public class BoardGame {
private final String name;
private final Category category;
private final AgeRange ageRange;
private final NumberOfPlayers numberOfPlayers;
private final Rating rating;
}
data class BoardGame ( val name: String,
val category: Category,
val ageRange: AgeRange,
val numberOfPlayers: NumberOfPlayers,
val rating: Rating
)
@PaulienVanAlst#Devoxx #Kotlin
Migrate PoJo’s
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
Rewrite unit tests
@Test
void when_game_is_rated_then_the_game_with_new_average_rate_is_returned()
@PaulienVanAlst#Devoxx #Kotlin
Rewrite unit tests
@Test
void when_game_is_rated_then_the_game_with_new_average_rate_is_returned()
@Test
fun `when game is rated then the game with new average rate is returned`()
@PaulienVanAlst#Devoxx #Kotlin
Rewrite unit tests
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version</version>
</dependency>
Business logic / integration tests
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<compilerPlugins><plugin>jpa</plugin></compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
Business logic / integration tests
@PaulienVanAlst#Devoxx #Kotlin
<plugin>
<groupId/>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration/>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noargs</artifactId>
<version>${kotlin.version</version>
<scope>test</scope>
</dependency>
</dependencies>
</plugin>
Business logic / integration tests
@PaulienVanAlst#Devoxx #Kotlin
Business logic / integration tests
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
Configuration
@SpringBootApplication
public class Application {
public static void main (String[] args) {
SpringApplication.run(Application.class, args);
}
}
@PaulienVanAlst#Devoxx #Kotlin
Configuration
@SpringBootApplication
public class Application {
public static void main (String[] args) {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication
open class Application
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
@PaulienVanAlst#Devoxx #Kotlin
Configuration
Code!
@PaulienVanAlst#Devoxx #Kotlin
Migration Plan
1. Set-up dependencies
2. Migrate PoJo’s
3. Rewrite unit tests
4. Business logic / integration tests
5. Configuration
@PaulienVanAlst#Devoxx #Kotlin
@PaulienVanAlst#Devoxx #Kotlin
@PaulienVanAlst#Devoxx #Kotlin
Thank you!
Rate this talk!
@PaulienVanAlst#Devoxx #Kotlin
@PaulienVanAlst#Devoxx #Kotlin
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin
J S
J V M
M U L T I P L A T F O R M
@PaulienVanAlst#Devoxx #Kotlin
So… what is Kotlin

More Related Content

Similar to Devoxx 2018: From Java to Kotlin: the adventures of a smooth migration

Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
JAXLondon2014
 
KazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo ScalabilityKazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo Scalability
2600Hz
 

Similar to Devoxx 2018: From Java to Kotlin: the adventures of a smooth migration (20)

Kubernetes: Learning from Zero to Production
Kubernetes: Learning from Zero to ProductionKubernetes: Learning from Zero to Production
Kubernetes: Learning from Zero to Production
 
Shift left-devoxx-pl
Shift left-devoxx-plShift left-devoxx-pl
Shift left-devoxx-pl
 
Rockstar Night - Spring, migrating to functional configuration
Rockstar Night - Spring, migrating to functional configurationRockstar Night - Spring, migrating to functional configuration
Rockstar Night - Spring, migrating to functional configuration
 
Hello to Kotlin
Hello to KotlinHello to Kotlin
Hello to Kotlin
 
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
 
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
 
TDD on Android (Øredev 2018)
TDD on Android (Øredev 2018)TDD on Android (Øredev 2018)
TDD on Android (Øredev 2018)
 
Data Driven DevOps
Data Driven DevOpsData Driven DevOps
Data Driven DevOps
 
Taming a beast - Cloudnative London 2018
Taming a beast - Cloudnative London 2018Taming a beast - Cloudnative London 2018
Taming a beast - Cloudnative London 2018
 
Elixir - Easy fun for busy developers @ Devoxx 2016
Elixir - Easy fun for busy developers @ Devoxx 2016Elixir - Easy fun for busy developers @ Devoxx 2016
Elixir - Easy fun for busy developers @ Devoxx 2016
 
Instan(t)a-neous Monitoring
Instan(t)a-neous MonitoringInstan(t)a-neous Monitoring
Instan(t)a-neous Monitoring
 
KazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo ScalabilityKazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo Scalability
 
2015 JavaOne EJB/CDI Alignment
2015 JavaOne EJB/CDI Alignment2015 JavaOne EJB/CDI Alignment
2015 JavaOne EJB/CDI Alignment
 
2015 JavaOne EJB/CDI Alignment
2015 JavaOne EJB/CDI Alignment2015 JavaOne EJB/CDI Alignment
2015 JavaOne EJB/CDI Alignment
 
Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?
 
vJUG24 - Spring Boot and Kotlin, a match made in Heaven
vJUG24 - Spring Boot and Kotlin, a match made in HeavenvJUG24 - Spring Boot and Kotlin, a match made in Heaven
vJUG24 - Spring Boot and Kotlin, a match made in Heaven
 
Integreation
IntegreationIntegreation
Integreation
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Bluemix Live Sync: Speed Up Maintenance and Delivery for Node.js
Bluemix Live Sync: Speed Up Maintenance and Delivery for Node.jsBluemix Live Sync: Speed Up Maintenance and Delivery for Node.js
Bluemix Live Sync: Speed Up Maintenance and Delivery for Node.js
 
ABCDs of Database Development
ABCDs of Database DevelopmentABCDs of Database Development
ABCDs of Database Development
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
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)

Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
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
 

Devoxx 2018: From Java to Kotlin: the adventures of a smooth migration