Skip to content
Learn Netverks

Lesson

Step 33/36 92% through track

java-interop

Java interoperability

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Java interoperability: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Kotlin runs on the JVM—calling Java libraries and migrating legacy codebases is a daily skill.

You will apply Java interoperability in contexts like: Migrating Spring Boot modules and sharing models with existing Java teams.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

Toward the end of the track—consolidate before capstone-style review lessons.

Kotlin and Java compile to the same JVM bytecode—call Java from Kotlin and vice versa without bridges. Mind platform types, nullability annotations, and JVM name mangling for top-level functions.

Calling Java from Kotlin

Java types without nullability annotations become platform types—treat them as nullable or not explicitly. SAM conversions let Kotlin lambdas implement Java functional interfaces.

Exposing Kotlin to Java

  • @JvmStatic on companion methods
  • @JvmOverloads for default parameters
  • @file:JvmName("Util") for top-level APIs

Important interview questions and answers

  1. Q: Platform type?
    A: Kotlin's relaxed type when Java lacks @Nullable/@NonNull—compile allows nullable or non-null calls at your risk.
  2. Q: Can Java use Kotlin extension functions?
    A: As static methods on a generated file class, e.g. StringsKt.capitalize(s).

Self-check

  1. What annotation exposes companion methods as Java statics?
  2. What is a platform type?

Pitfall: Java platform types (T!) need explicit null handling—annotate Java with @Nullable/@NonNull when possible.

Interview prep

Call Java from Kotlin?

Direct JDK and library use—no wrapper required.

Platform types?

Java nullability unknown—annotate Java or handle null explicitly.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • @JvmStatic when?
  • Platform types trap?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump