WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Core Java · Guru · question 97 of 100

What is a reactive system in Java? How is it different from traditional systems?

📕 Buy this interview preparation book: 100 Core Java questions & answers — PDF + EPUB for $5

A reactive system in Java is designed to handle and respond to a large number of incoming requests in a timely and efficient manner. It is built on the principles of reactive programming, which is a declarative programming paradigm focused on the processing of asynchronous data streams. In a reactive system, the application components are designed to be loosely coupled and communicate through messages, allowing for greater scalability and resilience.

A reactive system is different from traditional systems in several ways. Traditional systems typically rely on synchronous communication, which means that each request must be processed before the next request can be handled. This can lead to performance issues when handling a large number of requests, as the system may become overloaded and unable to respond in a timely manner. In contrast, a reactive system uses asynchronous communication, allowing requests to be processed concurrently without blocking or slowing down the system.

Another key difference is that reactive systems are designed to be resilient to failure. They use techniques such as redundancy, isolation, and circuit breakers to ensure that failures in one component do not cause the entire system to fail. Additionally, reactive systems are designed to be highly scalable, with the ability to handle a large number of concurrent requests without degradation in performance.

To implement a reactive system in Java, there are several frameworks and libraries available, such as Spring WebFlux, Akka, and Vert.x. These frameworks provide support for reactive programming constructs, such as reactive streams, and offer tools for building resilient and scalable systems.

Here’s an example of how Spring WebFlux can be used to create a reactive endpoint in Java:

@RestController
public class MyController {

    @GetMapping("/data")
    public Mono<String> getData() {
        return Mono.just("Hello World!");
    }
}

In this example, the @RestController annotation is used to define a REST endpoint. The @GetMapping annotation specifies the endpoint URL, and the Mono<String> return type indicates that the response will be a single string value wrapped in a reactive Mono object. The Mono.just("Hello World!") method call creates a new Mono object containing the string "Hello World!", which is returned to the client when the endpoint is called.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Core Java interview — then scores it.
📞 Practice Core Java — free 15 min
📕 Buy this interview preparation book: 100 Core Java questions & answers — PDF + EPUB for $5

All 100 Core Java questions · All topics