Mono class in Java what is, and when to use?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Mono is a Project Reactor type that represents an asynchronous computation producing zero or one value. It is the reactive equivalent of saying, “there may be one result later, or there may be none, or the operation may fail.” Use it when your workflow is naturally single-result and non-blocking, such as fetching one database row, calling one HTTP endpoint, or saving one entity.
What Mono Represents
A Mono can complete in one of three ways:
- emit one value and complete
- complete without a value
- terminate with an error
That makes it different from Flux, which can emit many values.
Even though the example is simple, the important idea is that the result is wrapped in a pipeline, not returned immediately as a plain value.
Use Mono for Single-Result Asynchronous Work
A good rule is simple:
- use
Monofor zero-or-one result operations - use
Fluxfor many-result operations
For example, a repository method that fetches one user by id is a natural Mono<User>.
In a real application, the value might come from a reactive database driver or a remote API call. The API still communicates the same contract: one result at most.
Transforming a Mono
Reactor becomes useful when you start composing work.
Use map when the transformation stays synchronous and returns a normal value.
Use flatMap when the next step itself returns a Mono.
That distinction matters because flatMap prevents nested reactive types such as Mono<Mono<String>>.
Mono Is Not the Same as Optional
A Mono<T> and an Optional<T> can both describe the presence or absence of a value, but they solve different problems.
Optional is synchronous and in-memory. Mono is asynchronous and part of a reactive stream pipeline. If your method already has the value right now, Optional may be enough. If the value arrives later from a non-blocking source, Mono is the better abstraction.
When Not to Use It
Do not introduce Mono just because Reactor is available. If the code is entirely synchronous and you are not composing reactive operations, adding Mono can make simple code harder to read.
Use it when the surrounding stack is reactive or when the operation itself benefits from non-blocking composition.
Common Pitfalls
- Using
Monofor collections when the real result is many items and should be aFlux. - Calling
.block()everywhere and losing the benefits of reactive composition. - Confusing
mapwithflatMap. - Treating
Monoas a thread rather than as a description of asynchronous work. - Wrapping already-simple synchronous code in
Monowithout a real need.
Summary
- '
Monorepresents an asynchronous result with zero or one value.' - It is appropriate for single-item operations such as one database lookup or one HTTP response.
- Use
mapfor synchronous transformations andflatMapfor reactive ones. - Prefer
Fluxwhen many items may be emitted. - Do not use
Monounless the problem is actually reactive or asynchronous.
Related reading

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.