Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Java started as an object-oriented language and has added lambdas, records, sealed types and pattern matching. How do you see the balance between object-oriented and functional styles in Java over the next decade, and what do you standardise?

Java now supports data-oriented programming: records and sealed types model data, and pattern matching implements operations over it, which suits domain data, messages and outcomes. Objects with behaviour remain the right tool for encapsulating mutable state, invariants and resources, and for services with several implementations. I would standardise immutable data types and pure domain calculations where practical, avoid importing styles that fight the language such as heavy monad stacks, and update the guidance only when new features become final, not while they are in preview.

Why this question is asked

For most of its life, Java code was organised around classes that bundle data with the methods that act on it. Lambdas, records, sealed types and pattern matching have changed what idiomatic Java looks like, and teams now argue about whether a domain model should be a class hierarchy with polymorphic methods or a set of records handled by switch. Interviewers ask this at a principal level because the answer sets standards that will shape a codebase for a decade. In this answer, we will recap how the toolbox changed, see what data-oriented programming looks like, look at where objects still win, compare the two on one example, and decide what to standardise and when to update it.

1How Java's Toolbox Changed

Java 8 added lambdas and streams, which made small functions cheap to write and pass around. Records, final in Java 16, gave us compact immutable data carriers with equals, hashCode and toString generated from their components. Sealed classes and interfaces, final in Java 17, let a type list exactly which subtypes it permits. And Java 21 finalised pattern matching for switch and record patterns, so we can take a value apart by its type and components, with the compiler checking that every permitted case is handled.

Together these support a style often called data-oriented programming: model data as plain, immutable, transparent values, model alternatives as sealed hierarchies, and write operations as functions that switch over the data. It is functional in spirit, but it uses only standard Java.

2Data-Oriented Programming in Practice

Here is a small example: the outcome of a shipping quote, modelled as data and handled by operations outside the types.

Java
sealed interface Quote {
record Priced(Money amount, int days) implements Quote {}
record Unavailable(String reason) implements Quote {}
record NeedsManualReview(String carrier) implements Quote {}
}
static String describe(Quote q) {
return switch (q) {
case Quote.Priced(Money m, int d) when d <= 1 -> "next day for " + m;
case Quote.Priced(Money m, int d) -> d + " days for " + m;
case Quote.Unavailable u -> "unavailable: " + u.reason();
case Quote.NeedsManualReview r -> "checking with " + r.carrier();
};
}

Notice that the records carry no behaviour beyond their data, and the operation, describe, lives elsewhere. If we add a new kind of Quote, every switch over Quote stops compiling until it handles the new case, which is a strong guarantee for data that many parts of the system interpret differently: user interfaces, logs, metrics and APIs.

3Where Objects With Behaviour Still Win

Objects remain the better tool when there is state to protect. A rate limiter, a connection pool or an in-memory aggregate with rules about how it may change all have invariants, conditions that must always hold, and the way to guarantee them is to hide the state behind methods that enforce the rules. A record exposes its components, so it cannot do that for mutable state.

Objects also win for resources and services. A class that owns a socket or a file implements AutoCloseable and manages its life cycle. A PaymentGateway interface with Stripe, Adyen and test implementations is classic polymorphism: the set of implementations is open, each hides its own details, and dependency injection selects one. Forcing that into a sealed hierarchy with a switch would be worse.

Java
final class TokenBucket { // state plus invariants: an object
private final int capacity;
private int tokens;
TokenBucket(int capacity) { this.capacity = capacity; this.tokens = capacity; }
synchronized boolean tryAcquire() {
if (tokens == 0) return false; // the invariant 0 <= tokens <= capacity
tokens--; // can only be broken from inside
return true;
}
synchronized void refill(int n) { tokens = Math.min(capacity, tokens + n); }
}

4Choosing Between the Two Styles

A useful way to decide is to ask what will change more often: the set of types or the set of operations. With sealed types and switch, adding a new operation is easy, just write another function, but adding a new type touches every switch. With interfaces and polymorphism, adding a new implementation is easy, but adding a new operation touches every class. This trade-off is old and well known, and Java now lets us pick per case rather than forcing one answer.

Which style fits which part of a system
SituationPreferReason
Domain data, events, messagesRecordsImmutable, transparent, easy to share
Closed set of outcomes or statesSealed types + switchCompiler checks every case
Many operations over stable dataSealed types + switchNew operation = new function
Mutable state with invariantsEncapsulating classOnly methods can change state
Resources (files, sockets, pools)Class + AutoCloseableOwns its life cycle
Open set of implementationsInterface + polymorphismNew implementation, no switch edits

5What I Would Standardise

I would make immutable data the default: records for domain values, events and DTOs, with mutable classes as a deliberate choice that needs a reason. I would standardise pure domain calculations where practical, keeping I/O in an outer layer, because that is what makes logic testable. Sealed types with pattern matching become the standard way to model closed sets of outcomes, replacing both exceptions for expected failures and boolean flags. Encapsulating classes remain the standard for stateful components and resources, and interfaces for services with several implementations.

I would discourage styles that fight the language, such as heavy monad stacks from functional libraries, point-free chains and deep currying. They come from languages with different syntax and type inference, and in Java they make code hard to read for most developers. The test for any imported style is whether a typical Java hire can read and change it without special training.

6Updating the Guidance as Java Evolves

Java keeps moving: primitive types in patterns are still in preview in Java 25, structured concurrency is still in preview, and value classes from Project Valhalla are in development. Each could change how we write data-oriented code. But preview features can change or be withdrawn between releases and require special compiler flags, so they do not belong in standards for production code.

So the rule is to update guidance when a feature becomes final, not when it first appears. Teams can experiment with previews in spikes or internal tools, and the standards owner collects that experience so the guidance is ready on the day the feature is final.

Step throughWhen a new language feature enters our standards
  1. Feature appears as previewexperiments in spikes only
  2. Collect team experiencewhat helped, what confused
  3. Is the feature final in our LTS?
    YesDraft guidance with examplesNoWait for the next release
  4. Publish in the standardswith before and after code

4 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Does data-oriented programming replace object-oriented design?

No. It replaces some uses of it, mainly class hierarchies built around data that many parts of the system interpret, where behaviour in the classes caused coupling. Encapsulation, interfaces and polymorphism stay essential for state, resources and pluggable services. Modern Java code uses both, often in the same module.

Why standardise on the LTS release rather than the latest one?

Most organisations run production on long-term support releases such as Java 21 or 25, so the standards should describe what teams can actually use. A feature final in Java 26 but not in our LTS is guidance for later.

How do you stop records from becoming anaemic models with logic scattered everywhere?

Records can still have small methods that derive values from their components, and compact constructors that validate them. The point is not to remove all behaviour from data, but to keep it to behaviour that depends only on the data, and to group operations in clearly named modules rather than scatter them.

8Conclusion

In this answer, we saw that records, sealed types and pattern matching make data-oriented programming natural in Java: immutable data, closed hierarchies and operations written as switches. Objects with behaviour remain the right tool for mutable state with invariants, resources and open sets of implementations. Standards should make immutable data and pure domain calculations the default, use sealed types for outcomes, keep classes for state and resources, avoid styles that fight the language, and adopt new features only once they are final.

What to say in the interviewAbout 80 seconds aloud

Open with

I see Java settling into a mix where each style has a clear job. Since records, sealed types and pattern matching became final, data-oriented programming is natural: model data as immutable records, model alternatives as sealed hierarchies, and write operations as switch expressions over them, where the compiler checks every case.

Then, if they want more

That fits domain values, events, messages and outcomes very well. But objects with behaviour aren't going away.

When there's mutable state with invariants, like a rate limiter or an aggregate, a class that hides its state behind methods is still the only way to protect it, and resources and pluggable services, like a payment gateway with several implementations, are classic object-oriented design.

A good rule of thumb is: if operations change more often than types, use sealed types and switch; if types change more often, use interfaces and polymorphism.

In our standards I'd make immutable records the default for data, pure domain calculations with I/O at the edges, and sealed results for expected outcomes, while classes stay the standard for state and resources. I'd discourage styles that fight the language, like heavy monad stacks.

And I'd only update the guidance when a feature is final in our LTS, not while it's in preview.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 16, Java 17, Java 25
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Java started as an object-oriented language and has added lambdas, records, sealed types...": https://scrivio-interview-library.netlify.app/java/functional-design/13d3714c19/