⚖️ The Short Answer Link to heading

For a new Spring Boot service, I’d pick Kotlin. Null safety the compiler checks, data classes with copy(), named and default arguments, and coroutines add up to less code and fewer runtime surprises, and Spring supports Kotlin as a first-class language.

Java is the better choice when your team, your hiring pipeline and your existing code are Java, and nobody has time to learn a second language well. Modern Java has closed part of the gap: records, sealed types, pattern matching and virtual threads cover a lot of what used to be Kotlin-only.

Both run on the same JVM, use the same libraries and frameworks, and call each other freely. You aren’t choosing an ecosystem, only a language for writing in it.

I wrote Java services for years before switching, and in early 2025 I wrote a one-sided case for Kotlin: Why Kotlin Beats Java for Backend Development. This post weighs both, against Java 25 and Spring Boot 4. If you want the case for Kotlin in general first, start with Why Kotlin?.


🧠 Null Safety: Still Kotlin’s Biggest Win Link to heading

In Kotlin, String can’t be null and String? can, and the compiler won’t let you call a method on a String? without handling the null first. A whole class of NullPointerException becomes a compile error.

fun greeting(user: User?): String =
    "Hello, ${user?.name ?: "guest"}"

Java has Optional, and annotations such as JSpecify’s @Nullable with a checker like NullAway. They help, but they’re opt-in: a field, a parameter or a collection element can still be null without anyone saying so.

Spring Boot 4 made this gap matter more. Spring’s own APIs now carry JSpecify nullability annotations, and Kotlin reads them as real nullable and non-null types, so a Spring API that returns String? forces you to handle the null. Java code calling the same API gets the same information only if you add a checker to the build. I wrote up what that change costs during an upgrade in Migrating a Kotlin Service from Spring Boot 3 to 4.

It shows up even in controllers. Spring reads Kotlin’s nullability, so a nullable parameter is an optional one:

@GetMapping("/search")
fun search(@RequestParam q: String?): List<Result> = searchService.search(q)
@GetMapping("/search")
public List<Result> search(@RequestParam(required = false) String q) {
    return searchService.search(q);
}

In Java, required = false and the possible null are two separate facts you keep in step by hand.


📦 Data Classes vs Records Link to heading

Java records closed most of the DTO gap. This is a complete, immutable value type in Java 16 and later:

public record User(String id, String name, String email) {}

The Kotlin equivalent is about as short:

data class User(val id: String, val name: String, val email: String)

The differences are in what you do next:

  • Changing one field. A data class has copy(email = newEmail). A record has no equivalent yet, so you write a withEmail method per field, or call the constructor with every field again.
  • Defaults and named arguments. User(id = "1", name = "Ada", email = "ada@example.com") reads clearly with six fields, and a field with a default can be left out. Java has neither, so a record with many fields usually grows a builder.
  • Null safety on the fields. A Kotlin email: String can’t hold null. A record’s String email can.

Records are good enough that “boilerplate” is no longer a strong argument on its own. copy(), defaults and named arguments still are. There’s more on using data classes well in Why Kotlin Data Classes Shine.


🧱 Spring Beans and Dependency Injection Link to heading

Constructor injection is the idiom in both languages, and neither needs @Autowired on a single constructor:

@RestController
class UserController(private val users: UserService) {
    // ...
}
@RestController
public class UserController {
    private final UserService users;

    public UserController(UserService users) {
        this.users = users;
    }
}

Kotlin’s primary constructor saves the field and the assignment. It’s a small win per class, and it adds up across a service with a hundred beans.

There’s one catch on the Kotlin side. Kotlin classes are final by default, and Spring needs to subclass some of them: @Configuration classes, and beans with @Transactional or @Cacheable methods. The kotlin-spring compiler plugin opens those classes for you, and Spring Initializr adds it to every Kotlin project. Forget it in a hand-made build and you’ll get confusing proxy errors.


🧰 Language Features That Replace Patterns Link to heading

What you need Java Kotlin
Value types and DTOs Records data class
Optional values Optional<T> or @Nullable Nullable types (T?)
Many constructor parameters Builder pattern Named and default arguments
Helpers on types you don’t own Static utility classes Extension functions
Closed sets of types Sealed interfaces and pattern matching (Java 21) Sealed interfaces and when
Builders for nested config Fluent builders Type-safe builders and DSLs

Java 21 closed the sealed-types row: a switch over a sealed interface is checked for completeness, just like Kotlin’s when. Records narrowed the first row, as the section above shows. The rest are still Kotlin’s.


🧵 Concurrency: Coroutines vs Virtual Threads Link to heading

This is where modern Java changed the comparison most. Before Java 21, scaling a service with many slow I/O calls meant reactive code (Reactor, WebFlux) or Kotlin coroutines. Now virtual threads let plain blocking code scale: one spring.threads.virtual.enabled=true and each request gets a cheap thread.

Coroutines still do things virtual threads don’t:

  • Structured concurrency that’s stable today. Starting several calls at once and cancelling the rest when one fails is a few lines with coroutineScope and async. Java’s structured concurrency API is still in preview.
  • Streams. Flow handles a stream of values with backpressure. Virtual threads have no equivalent.
  • WebFlux without Mono and Flux. Spring’s coroutine support lets a reactive stack read like sequential code.

If all you need is blocking code that scales, virtual threads work from either language, so this one isn’t a reason to switch. I compared all three approaches on the same endpoint in Coroutines vs Reactor vs Virtual Threads in Kotlin.


🐘 Where Java Wins Link to heading

Kotlin has real costs, and they’re the reasons I’d stay with Java in some teams:

  • People. There are far more Java developers than Kotlin developers. If you hire often, or your developers rotate across many Java codebases, a second language is a real cost.
  • Build speed. Kotlin compiles more slowly than Java. The K2 compiler narrowed the gap, but a large Kotlin module still builds noticeably slower.
  • Upgrades. A Kotlin service tracks two release trains, Kotlin’s and the JDK’s, and the Kotlin compiler sometimes changes behaviour in ways you have to test for. My notes on Kotlin 2.4 show what a typical release costs.
  • JPA. Hibernate expects open classes with no-argument constructors and mutable fields. Kotlin needs the kotlin-jpa plugin, which opens entity classes and gives them no-argument constructors, and data classes are a poor fit for entities. It works, but it’s friction that Java doesn’t have.
  • Tooling outside IntelliJ. Kotlin support in other editors and in some static-analysis and code-coverage tools still trails Java’s.
  • Java is moving. Records, pattern matching, text blocks and virtual threads all arrived within a few years, and the six-month release cadence keeps adding more. The gap is smaller every year.

None of these are about runtime performance. Kotlin and Java compile to the same bytecode and run on the same JVM, so a service is as fast in one as the other.


🧭 How I’d Choose Link to heading

Your situation My pick
New Spring Boot service, team open to Kotlin Kotlin
Team that already writes Kotlin, on Android or elsewhere Kotlin
Large existing Java codebase, steady team Java, and Kotlin for new modules if the team wants it
You hire often, or rotate developers across many Java services Java
Heavy JPA domain model Either, but expect friction with Kotlin
Lots of concurrent I/O, mostly blocking code Either: virtual threads work in both
Streams of data, or many concurrent calls to cancel together Kotlin, with coroutines and Flow

You don’t have to switch everything at once. Kotlin and Java can live in the same module, call each other directly, and share the same Spring context. The low-risk way to try Kotlin is to write the next new service, or the tests of an existing one, in it.


✅ Conclusion Link to heading

In 2026 the honest comparison is closer than it was. Java fixed the boilerplate. It still lacks compiler-checked null safety, copy(), named and default arguments, and coroutines, and those are what I’d miss most going back.

If your team can take on a second language, Kotlin is the better language for Spring Boot services. If it can’t, modern Java is a good place to be, and much better than the Java I left.


Sources


Related Posts