SlideShare a Scribd company logo
NEW BEST FRIENDS:
Kotlin’s Interoperability with Java
Presented by: David Greenhalgh
TODAY’S FORMAT
Housekeeping/Intro
Kotlin Talk by David
Live Q&A
Lunch & Learn / Book Giveaway
BIG NERD RANCH
Travel to your office Discuss Kotlin
Enjoy lunch!
BUILD BRILLIANCE
BIG NERD RANCH
• Immersive BOOTCAMPS
• Onsite TEAM TRAINING
• THE FRONTIER subscription
• Digital PRODUCT
DEVELOPMENT
4
BIG NERD RANCH
BIG NERD RANCH
BIG NERD RANCH
Travel to your office Discuss Kotlin
Enjoy lunch!
How Kotlin Interoperates with Java
Why Kotlin?
• Concise
• Pragmatic
• Flexible
• Type-safe
Why Kotlin?
• Concise
• Pragmatic
Java
person.getName();
Kotlin
person.name
Why Kotlin?
• Type-safe
Objects may not hold null values unless declared using a nullable type
String may not be null
String? may be null
Why Kotlin?
• Full interoperability with Java
Interoperability
Kotlin code and Java code works together directly
• Call Java methods from Kotlin
• Call Kotlin functions from Java
The Kotlin Compilation Process
Kotlin compiles down to Java bytecode
JVM Bytecode
Decompiled Java Bytecode
Interoperability
Kotlin code and Java code works together directly
• Leverage legacy Java frameworks (e.g. Android)
• Gradually transition your codebase from Java to Kotlin
An Example
• Calling a Java method from Kotlin
• Nullability and platform types
• Accessing Java fields from Kotlin
• Type mapping
• Kotlin file anatomy
A Java Method
public class Jhava {
public String utterGreeting() {
return "BLARGH";
}
}
Calling a Java Method from Kotlin
fun main(args: Array<String>) {
val adversary = Jhava()
println(adversary.utterGreeting())
}
Another Java Method
public class Jhava {
public String utterGreeting() {
return "BLARGH";
}
public String determineFriendshipLevel() {
return null;
}
}
Platform Type
NullPointerException in Kotlin
fun main(args: Array<String>) {
...
val friendshipLevel = adversary.determineFriendshipLevel()
println(friendshipLevel.toLowerCase())
}
Nullability Annotations
public class Jhava {
@NotNull
public String utterGreeting() {
return "BLARGH";
}
@Nullable
public String determineFriendshipLevel() {
return null;
}
}
IntelliJ Nullable Type Awareness
Java Field with Getter and Setter
public class Jhava {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Property Reference from Kotlin
fun main(args: Array<String>) {
Jhava().name
}
Type Mapping
Some Kotlin types map directly to Java types
• String to String
Type Mapping
Other Kotlin types do not map directly to Java types
• Kotlin's Int to Java's int
Primitive Types
• Java represents basic data types using "primitve types" (non-objects)
• Kotlin represents all data using objects
Integers in Kotlin
fun main(args: Array<String>) {
val adversary = Jhava()
val adversaryHitPoints: Int = adversary.hitPoints
adversaryHitPoints.dec()
println(adversaryHitPoints.javaClass)
}
>>> int
Kotlin File Anatomy
• Java files contain exactly one class
• Kotlin files may contain classes, functions, and variables at top-level
• How can you call standalone Kotlin functions from Java?
A Standalone Kotlin Function (Hero.kt)
fun main(args: Array<String>) {
...
}
fun makeProclamation() = "Greetings, beast!"
Calling a File-level Function from Java
public static void main(String[] args) {
System.out.println(HeroKt.makeProclamation());
}
Customizing Class Name (Hero.kt)
@file:JvmName("Hero")
fun main(args: Array<String>) {
...
}
fun makeProclamation() = "Greetings, beast!"
Using the Customized Class Name
public static void main(String[] args) {
System.out.println(Hero.makeProclamation());
}
Customizing Compiled Java Code
JVM annotations exist to customize the Java code that is compiled from
your Kotlin source
• @JvmName
• @JvmOverloads
• @JvmStatic
• @JvmField
Refrain: Your Upgrade Path
Kotlin compiles down to Java bytecode
Risks of Sticking with Java
• Slow moving language development
• Less type-safe
• Less concise
• Less interest from developers
Next Steps
• Start a new project in Kotlin
• Upgrade selectively
• Acquire Kotlin resources

More Related Content

PDF
Dear Kotliners - Java Developers are Humans too
PPTX
Introduction to Koltin for Android Part I
PDF
A quick and fast intro to Kotlin
PPTX
Kotlin presentation
PDF
Kotlin Types for Java Developers
PPTX
Oopsecondgrouppresentation 180726073512-converted (1)
PDF
Kotlin Overview
KEY
Java Building Blocks
Dear Kotliners - Java Developers are Humans too
Introduction to Koltin for Android Part I
A quick and fast intro to Kotlin
Kotlin presentation
Kotlin Types for Java Developers
Oopsecondgrouppresentation 180726073512-converted (1)
Kotlin Overview
Java Building Blocks

What's hot (13)

PPTX
04 Java Language And OOP Part IV
PPTX
Polymorphism
PPTX
05 Java Language And OOP Part V
PPTX
Paca oops slid
PPTX
To Lombok or not to Lombok | J-Fall 2019
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
PPTX
PDF
Java essentials for hadoop
PDF
From DOT to Dotty
PPTX
06 Java Language And OOP Part VI
PPT
Object-Oriented Programming Concepts
04 Java Language And OOP Part IV
Polymorphism
05 Java Language And OOP Part V
Paca oops slid
To Lombok or not to Lombok | J-Fall 2019
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
Java essentials for hadoop
From DOT to Dotty
06 Java Language And OOP Part VI
Object-Oriented Programming Concepts
Ad

Similar to Kotlin's Interoperability with Java (20)

PDF
Programming with Kotlin
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PDF
Kotlin Online Training.pdf
PPTX
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
PDF
Kotlin Online Training.pdf
PPSX
Kotlin Language powerpoint show file
PPTX
Kotlin Presentation
PDF
Intro to Kotlin
PPTX
Getting Started With Kotlin
PDF
Transitioning Android Teams Into Kotlin
PPTX
Kotlin for Android - Goto Copenhagan 2019
PDF
Kotlin from-scratch
Programming with Kotlin
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Online Training.pdf
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Online Training.pdf
Kotlin Language powerpoint show file
Kotlin Presentation
Intro to Kotlin
Getting Started With Kotlin
Transitioning Android Teams Into Kotlin
Kotlin for Android - Goto Copenhagan 2019
Kotlin from-scratch
Ad

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administraation Chapter 3
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
L1 - Introduction to python Backend.pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ai tools demonstartion for schools and inter college
System and Network Administraation Chapter 3
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Reimagine Home Health with the Power of Agentic AI​
medical staffing services at VALiNTRY
AI in Product Development-omnex systems
How to Migrate SBCGlobal Email to Yahoo Easily
L1 - Introduction to python Backend.pptx
Softaken Excel to vCard Converter Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Essential Infomation Tech presentation.pptx
Transform Your Business with a Software ERP System
Wondershare Filmora 15 Crack With Activation Key [2025
Odoo Companies in India – Driving Business Transformation.pdf
Upgrade and Innovation Strategies for SAP ERP Customers

Kotlin's Interoperability with Java

  • 1. NEW BEST FRIENDS: Kotlin’s Interoperability with Java Presented by: David Greenhalgh
  • 2. TODAY’S FORMAT Housekeeping/Intro Kotlin Talk by David Live Q&A Lunch & Learn / Book Giveaway
  • 3. BIG NERD RANCH Travel to your office Discuss Kotlin Enjoy lunch!
  • 4. BUILD BRILLIANCE BIG NERD RANCH • Immersive BOOTCAMPS • Onsite TEAM TRAINING • THE FRONTIER subscription • Digital PRODUCT DEVELOPMENT 4
  • 7. BIG NERD RANCH Travel to your office Discuss Kotlin Enjoy lunch!
  • 9. Why Kotlin? • Concise • Pragmatic • Flexible • Type-safe Why Kotlin? • Concise • Pragmatic Java person.getName(); Kotlin person.name
  • 10. Why Kotlin? • Type-safe Objects may not hold null values unless declared using a nullable type String may not be null String? may be null Why Kotlin? • Full interoperability with Java
  • 11. Interoperability Kotlin code and Java code works together directly • Call Java methods from Kotlin • Call Kotlin functions from Java The Kotlin Compilation Process Kotlin compiles down to Java bytecode
  • 13. Interoperability Kotlin code and Java code works together directly • Leverage legacy Java frameworks (e.g. Android) • Gradually transition your codebase from Java to Kotlin An Example • Calling a Java method from Kotlin • Nullability and platform types • Accessing Java fields from Kotlin • Type mapping • Kotlin file anatomy
  • 14. A Java Method public class Jhava { public String utterGreeting() { return "BLARGH"; } } Calling a Java Method from Kotlin fun main(args: Array<String>) { val adversary = Jhava() println(adversary.utterGreeting()) }
  • 15. Another Java Method public class Jhava { public String utterGreeting() { return "BLARGH"; } public String determineFriendshipLevel() { return null; } } Platform Type
  • 16. NullPointerException in Kotlin fun main(args: Array<String>) { ... val friendshipLevel = adversary.determineFriendshipLevel() println(friendshipLevel.toLowerCase()) } Nullability Annotations public class Jhava { @NotNull public String utterGreeting() { return "BLARGH"; } @Nullable public String determineFriendshipLevel() { return null; } }
  • 17. IntelliJ Nullable Type Awareness Java Field with Getter and Setter public class Jhava { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
  • 18. Property Reference from Kotlin fun main(args: Array<String>) { Jhava().name } Type Mapping Some Kotlin types map directly to Java types • String to String
  • 19. Type Mapping Other Kotlin types do not map directly to Java types • Kotlin's Int to Java's int Primitive Types • Java represents basic data types using "primitve types" (non-objects) • Kotlin represents all data using objects
  • 20. Integers in Kotlin fun main(args: Array<String>) { val adversary = Jhava() val adversaryHitPoints: Int = adversary.hitPoints adversaryHitPoints.dec() println(adversaryHitPoints.javaClass) } >>> int Kotlin File Anatomy • Java files contain exactly one class • Kotlin files may contain classes, functions, and variables at top-level • How can you call standalone Kotlin functions from Java?
  • 21. A Standalone Kotlin Function (Hero.kt) fun main(args: Array<String>) { ... } fun makeProclamation() = "Greetings, beast!" Calling a File-level Function from Java public static void main(String[] args) { System.out.println(HeroKt.makeProclamation()); }
  • 22. Customizing Class Name (Hero.kt) @file:JvmName("Hero") fun main(args: Array<String>) { ... } fun makeProclamation() = "Greetings, beast!" Using the Customized Class Name public static void main(String[] args) { System.out.println(Hero.makeProclamation()); }
  • 23. Customizing Compiled Java Code JVM annotations exist to customize the Java code that is compiled from your Kotlin source • @JvmName • @JvmOverloads • @JvmStatic • @JvmField Refrain: Your Upgrade Path Kotlin compiles down to Java bytecode
  • 24. Risks of Sticking with Java • Slow moving language development • Less type-safe • Less concise • Less interest from developers Next Steps • Start a new project in Kotlin • Upgrade selectively • Acquire Kotlin resources