liveBook · Manning

Imperative programming

As explained in Quarkus in Action

Imperative code is code that expresses computation as an ordered sequence of commands that directly change program state.

Imperative programming expresses computation as an ordered sequence of statements that describes how a program operates. A runtime invokes an entry point, such as Java’s main method, and executes those statements step by step. section 1.3.1 section 8.1.2

The model is straightforward for sequential work, but blocking I/O can occupy a worker thread from request start to completion. Database, filesystem, network, and broker operations may therefore increase thread, memory, and CPU demands under concurrent load. section 8.1.1

In Quarkus, imperative programming is a supported execution style rather than a required architecture:

  • Write applications using the familiar sequential model, even though Quarkus uses a reactive engine internally. section 1.3.1
  • Combine imperative and reactive code, including within the same application or class, to make a gradual transition. section 8.1 section 8.6
  • Consider reactive programming or virtual threads when responsiveness and scalability under heavy traffic matter, while accounting for their respective limitations. section 1.3.1 section 8.1

Sequential request processing

A Java entry point executes statements in order. When one statement performs a blocking database or network call, the request’s worker thread waits before the next statement can proceed. Reactive execution instead schedules continuation code for the operation’s completion. section 8.1.1 section 8.1.2

Figure 8.1 Blocking I/O request handling: threads are blocked while waiting for an I/O operation to complete
figure

Compare how blocking I/O keeps request-handling threads waiting while operations complete. section 8.1.1

How Quarkus in Action covers it

How deep it goes
Defines sequential execution and explains blocking I/O consequences, but stops short of detailed imperative implementation syntax.
Examples
Uses Java entry-point execution and sequential database, filesystem, network, or message-broker I/O as concrete examples.
What it assumes
Assumes familiarity with Java-style statements and entry points while explaining the imperative model for developers new to reactive programming.
What you can do after
Apply it via Quarkus by writing sequential code, then combine it with reactive code or virtual threads when requirements change.
How it connects
Connects imperative programming with reactive programming, event-driven architecture, nonblocking I/O, and virtual threads.

Also explained in

Compare how 14 books explain imperative programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.