mattone
dopo mattoneTHE BOOK SERIES
IT/EN
← Java guide

Java 25 · 39/39

Conclusions. Keep building, brick by brick

Java 25 · Complete guide · Draft under review

Read the editorial note for the review status.

Search the whole guide →

To conclude

If you have made it this far, Java, Brick by Brick has at least kept you company for a good stretch of the journey. I also hope it has left you with something more lasting than the syntax of a construct or the name of a JDK class. APIs change; the way we approach a problem, explain a choice and leave our work understandable to whoever comes next remains.

Of all the things we have encountered in the book, I would like a love of good code and a desire to improve to stay with you. Writing well is not merely a source of personal satisfaction. It is a way of respecting colleagues, the company and clients: it makes it easier to fix a defect, adapt a requirement and understand whether a change has caused damage. A program that works today but that nobody dares touch tomorrow has solved only part of the problem.

In these pages we have encountered objects, types, collections, functions, threads, files, networking, build tools and diagnostics. I would not like you to come away with a list of names to remember. Every brick had a reason: recognizing a difficulty, seeing why the previous solution was not enough, building the next one and verifying it. If tomorrow you face a library, an HTTP service or a program that hangs, the useful question will not be “which chapter should I copy?”. It will be “where is the boundary of the problem, which property must I preserve, and which test will tell me that I have chosen well?”.

The method we take beyond the book. When facing a new task, we first describe the observable result and the case that could fail. We then choose the smallest solution capable of respecting that contract. We test it, discover its limit and adapt it to the real context. This process does not guarantee that we will make no mistakes; it makes mistakes visible and correctable.

Naming the right thing

When we open a file written by someone else, our first questions are simple: what does this class represent? What does the method promise? Where does this data come from? If the names are opaque, we have to execute the program in our heads before even understanding which problem it tackles. var1 and var2 save the writer a few keystrokes and demand many more from the reader. A name such as availableQuantity does not remove the need to verify the rule, but it tells us which question to ask. Likewise, tan() may be enough within a strictly declared mathematical context; calculateTangentAngle() says more when that context is not obvious. The best name depends on the responsibility and the audience of the code, rather than its length.

We have seen this choice in the catalog in the final chapters. MAX_LINE and MAX_TITLES declare different limits. If we called both of them LIMIT, readers would have to trace their usage every time to understand which resource we were controlling. If, on the other hand, a method is called read but saves to a database or sends network requests, its name lies. Either we change the name to represent the effect, or we separate the responsibilities. A good name is a small, verifiable promise.

Let us not turn the rule into a competition for the longest name, though. variableThatDoesThisAndThat remains vague, even if it occupies half a line. A useful name identifies the domain concept or the intention of the operation. If we cannot find one, perhaps we have not understood the task well enough yet. Stopping to discuss a name can bring to light two meanings that we had confused in the code.

It is all reading and writing, but we must know what

I remember Gaetano Barbagallo, my first project leader. When a task seemed enormous, he brought me back to a very concrete question: what do we read, what do we transform and what do we write? Over the years, that simplicity has stayed with me. It does not mean that every system is trivial. It means that we can look for observable steps instead of leaving everything in a thousand-line method and hoping that the debugger will save us.

Take catalog import once again. We read characters from a source; split them into lines; normalize the titles; check two limits; and finally return a result. When the source becomes an HTTP response, we add timeouts and a maximum size. When the destination becomes a database, we decide whether the new archive must appear all at once. The “read and write” path is not a slogan that erases risks: it is a guide to discovering where they arise and who must handle them.

A class should represent a responsibility that we can explain. A method should provide an operation with an understandable contract. If part of the problem is too large, dividing it can make it testable. But dividing does not mean creating dozens of tiny classes for no reason. Composition, interfaces and sometimes inheritance are tools, not prizes for a complicated diagram. We use them when they clarify a boundary or a behavior that can be replaced; otherwise we choose the most direct form.

From the problem to the structure. If changing a title rule forces us to change the HTTP client and the code that draws a screen, we have coupled responsibilities that change for different reasons. If instead we split an algorithm into ten methods that call one another without offering a recognizable concept, we have merely moved the complexity. The criterion is to ask which decision belongs to each part and which test protects it.

Leaving what is needed in the source

One practice I have often encountered is keeping the old version of a method as a commented-out block next to the new one. At first this looks prudent. After a few changes, nobody knows whether that block represents a valid alternative, a failed experiment or a forgotten fragment. Readers have to work through two overlapping programs to understand which one the JVM executes. Version control keeps history more reliably: we can find a version, read why it was changed and, if necessary, retrieve it through an explicit decision. In the current source, we leave the code needed for the current behavior.

This does not mean eliminating every comment. A useful comment explains what the code alone cannot show well: why we imposed a limit of one hundred titles, which external format we must respect, which library anomaly we worked around and when we will be able to remove that workaround. A comment such as // loop through the whole array next to for (int i = 0; i < array.length; i++) repeats the obvious. Worse, it can become false if the code changes and the comment remains. If an operation is difficult to explain, let us first try better names and separate its steps; then document the reason that syntax does not reveal.

Javadoc also has a precise responsibility. In the build chapter we documented the catalog's inputs, results and errors. A successfully generated HTML page does not prove that the contract is correct: if the method now closes the supplied Reader and the documentation says nothing, we have hidden an important effect. Useful documentation is read together with the tests and changes together with the behavior.

Conventions and readability are an agreement with others

A project's conventions help us predict where to find a class, what a method will be called and where the tests are. Java has recognizable forms for packages, classes, methods and constants. We may have reasons to depart from a convention, but a random deviation forces every colleague to start again from scratch. Staying consistent within the project reduces the work of interpretation. It is a form of collaboration, not a matter of personal taste imposed from above.

Readability does not mean the smallest number of lines. Compressing ten steps into one expression can be fun; the question is whether the next reader will be able to locate the error when the result is wrong. Conversely, splitting a simple rule into a maze of helpers can make it worse. In the chapter on Streams we saw that a pipeline works well when every step has a meaning and the order remains visible. If an explicit loop makes resource closure or the point where reading stops clearer, that loop is a better choice for that problem.

Let us also think of those who will use the code without having read this book. A precisely named test, an error message that distinguishes malformed input from an inaccessible file, a log that does not expose confidential titles, and a JAR that starts using the stated instructions are all acts of communication. Source quality does not end at the closing brace: it includes how the program presents itself to those who must run, diagnose and modify it.

Choosing the tool after recognizing the problem

You sometimes hear: “Let us use this framework, so we can finish sooner”. Sometimes that really will be the right choice. But first we must know what the program must do, which constraints it has and what we introduce by adopting that tool. If the requirement is to read a two-line file, adding an entire platform can complicate distribution and maintenance. If instead the program must manage many users, persistence, security and observability, pretending that the same teaching class is enough would be just as naive.

We saw this with concurrency tools. An AtomicInteger helps when several threads atomically update one variable. It does not automatically turn a reservation that modifies availability, an order and a payment into an indivisible transaction. A virtual thread allows us to maintain a direct style for many tasks that wait for I/O, without reserving a platform thread throughout the wait; it does not magically speed up a computation that saturates the CPU. In both cases the API name comes after describing the invariant or the bottleneck. The right solution is the one that answers the concrete question and passes a relevant test.

The same applies to the Vector API, still incubator in this volume's Java 25 path, and to native memory access: these are fascinating subjects, but they require specific conditions, costs and risks. Choosing to study them is useful; choosing to use them in production requires a problem that justifies them. A benchmark without representative load or a green build without boundary tests is not sufficient evidence.

Learning from others, then refactoring with a test

To grow, we should read code written by more experienced people, but also code different from our own. Let us look at how a project handles errors, where it places tests, which decisions it explains in comments and which it leaves to the structure. Let us ask why a solution was chosen instead of merely copying its form. Open code can teach us a lot; a respectful review among colleagues also makes assumptions visible that we would not have noticed alone. People receiving a question are often happy to explain a choice: it is one of the best parts of our profession.

Refactoring means improving structure while preserving the agreed observable behavior. First we need a test that makes that behavior recognizable. Then we can change one step at a time: rename a variable, extract a rule, replace real duplication, recompile and rerun the checks. If we introduce a new limit, on the other hand, we change the contract: we call it what it is and add tests for accepted and rejected cases. This distinction prevents a functional change from hiding behind the reassuring label of “cleanup”.

The suggestion I wrote years ago—first make it work, then optimize it, finally make it prettier—needs one clarification: working means meeting the requirement and having adequate evidence, not displaying a green screen just once. Measure before optimizing; reread before making it elegant; repeat tests afterward. When a colleague opens the change, they must be able to understand which problem we solved and why the new form is easier to maintain.

Continuing to follow Java without chasing every novelty

Amber, Loom, Panama and Valhalla represent different paths in the platform’s evolution. This volume uses Java 25 as its reference. Some ideas are now stable parts of the platform: for example, virtual threads, described in chapter 20, were finalized in Java 21; the Foreign Function and Memory API, examined in chapter 28, was finalized in Java 22. Amber accompanied features we now use normally, such as local inference with var, text blocks, records and sealed hierarchies. Valhalla continues to explore value objects; in Java 25 we do not treat value classes as a stable feature to use in the book's programs.

How to read about a new feature. A project page tells us about a direction; a JEP describes the objectives, compromises and status of a proposal; the specification and release documentation tell us what is available in the JDK we are using. Before adopting a feature, check its release, stable/preview/incubator status, required options, compatibility and use cases. Then write a small program and test it in your environment. “Announced” and “available in Java 25” are not synonyms.

There is no need to predict today which API will be indispensable next. We need to preserve our ability to learn. When a new release arrives, start from the problem you have, read the official notes and ask which part of your model really changes. Shorter syntax can make a case expressive; it does not automatically clarify a domain decision. A new diagnostic tool can show more data; it does not decide by itself which behavior is correct. The programmer's work remains connecting that data to the right questions.

I hope this book has given you the courage to ask those questions, try a solution, discover where it fails and build the next brick. Never stop trying to understand the code you write and the code entrusted to you. Good code is not a destination: it is a shared practice, made of well-recognized problems, explainable choices and checks that allow others to continue.

To verify the journey

The concluding activities ask you to start from a requirement, recognize the boundaries it may cross and justify a solution with evidence. Choose a program from the book that you have modified: explain the original problem, the invariant you protected, a positive test and a case that could disprove the solution. Then imagine a colleague must extend it to a new data source. Which part of the model can they reuse and which contract must they verify again? If you can answer without limiting yourself to an API name, you have acquired the method that holds the chapters together.

References for following the language

The technical status recalled in these Conclusions refers to Java 25, verified on October 2, 2026. JEP 444 on virtual threads records them as a feature delivered in Java 21; Oracle's Foreign Function and Memory API documentation documents finalization in Java 22 and refers to JEP 454. The proposal establishing Project Amber clarifies its objective; the Java 25 specifications in the preceding chapters document the individual features. The official Project Valhalla site distinguishes subsequent experiments from what is included in Java 25. Future updates require checking these sources and the notes for the release in use again, rather than reusing this snapshot as though it were timeless.

Try the examples

Running the programs requires JDK 25. Download the individual Java files linked in the chapter or the complete example project, which includes instructions and a launcher script. The explanations also compare expected output: predict it before running the program.

Massimiliano Tarquini · CC BY-NC 4.0

Back to the top ↑