When I began writing the first version of Java, Brick by Brick in 2000, I had no idea that the text would keep circulating for so long. I put it online for free and, within a few days, it began passing from one programmer to another. There was no distribution plan: there were people who found it useful and recommended it. Years later, I kept spotting it on desks, often beside books and tools that had arrived much later. For someone who had started by putting pages together to explain Java, it was a surprise that was hard to forget.
Then came the Hoepli edition. It was 2002, and the book was presented at SMAU. The copies available at the stand sold out within a few days. I still remember the excitement of seeing it in the window of a university bookshop: a book that, until shortly before, had existed only in my files had become an object that someone else could pick up, read, and perhaps use to solve a problem. That shop window was more than a personal milestone. It told me that the method I had used to try to build the explanations, one brick after another, had reached readers I did not know.

I owe a great deal to this book. It opened professional doors for me and allowed me to meet people from whom I learned. It is a debt that cannot be settled simply by thanking readers: it also asks me not to leave them holding a frozen picture of the language. When I encountered Java in 1996, many things we now take for granted did not yet exist. Since then, the language, the libraries, and the platform have changed; some of the early ideas have become habits, while others have been corrected or abandoned. The way we write, distribute, and check software has changed too.
Returning to the book therefore means doing two jobs at once. The first is to update what readers will use when they open a current JDK. The second, more delicate job is to preserve the way these pages guide readers: a concrete question, the steps needed to answer it, an example to follow, and the exceptions that keep us from learning the wrong rule. I do not want the update to erase the memories, the analogies, or the patience of the explanations. The update follows this principle: make the path clearer and connect each new feature to the problem it helps solve.
The technical reference for these pages is Java 25. The abbreviation LTS, associated with this version in the Oracle support roadmap, concerns a distribution's support lifecycle: it does not mean that every program must be updated immediately, nor that every new language feature originated in Java 25. When a construct was introduced in an earlier version, I will say so where the information really helps you understand or use it. Some examples may show a historical solution, but the main path will use stable tools relevant to the reference version.
Java version – What the main pages teach. A stable feature is part of the language or APIs according to the specification for the stated version. A preview feature is available to try, but may change and requires explicit options. An incubator API belongs to experimental modules. The last two cases will appear, where useful, in separate further reading sections: no reader should mistake an experiment for ordinary Java 25 syntax. The official Java 25 documentation is the reference for this distinction.
The Book That Does Not Exist
I remember well the feeling of looking for a precise explanation and finding scattered fragments instead: a page that assumed you knew the terminology, an example that skipped the decisive step, a book that kept starting again from what I already knew. I was looking for the book that was not there, one that would help me grow without making me read everything in the same way. Over time, I also came to understand something else: knowing Java syntax alone is not enough to write understandable, reliable software.
Anyone who has ever lost an afternoon searching for a single piece of information knows what I mean. The problem is not always a lack of documentation: often, it is fragmentation. You find a method's signature, but not the reason you should use it; you find an example that works, but not the case in which it fails; you find a complete explanation, but if you already know the first steps, you must go through all of it to reach the question that interests you. The “book that does not exist” was the wish to bring depth and freedom of reading together, without asking every reader to pretend to start from the same point.
This book tries to meet both needs. Beginners can start with the simplest concepts, try an example, and return to a point that is not yet clear. Those who already program can quickly reach the topics they are missing or compare their habits with more recent tools. Advanced sections are clearly identified; putting them off is a normal choice, not a defeat. They are the bricks to add when the structure underneath is ready.
I have not written two separate books, one for beginners and one for experts. I have tried to create a path where beginners are not abandoned at the first new term, and experienced readers can skip a familiar foundation without losing the thread. That is why a further reading section can be set aside and revisited later, but the main explanation must not depend on what is hidden inside it. Likewise, a new Java feature will not be presented as a trick to copy: we will see what problem it solves, how it changes an example we already understand, and what limitations remain.
Key concept – One brick at a time. A new term is explained when it is needed; code is introduced before it is shown and then read alongside its result. If an example uses a concept that comes later, the cross-reference is explicit. Readers should not have to guess the missing step.
The path begins with the way we think about a program and the tools needed to run it. It continues with syntax, objects, types, APIs, and concurrency; it then reaches building, checking, and maintaining code. The more advanced parts require a few more foundations, but they do not change the original promise: every chapter must explain why a problem matters, how to approach it, and what limitations the demonstrated solution has.
The path is organised into three parts. In the first, we build the language: we start with statements and reach classes, objects, and the tools Java uses to express a model. Recognizing a keyword is not enough; I want you to be able to read a program and predict what happens when you run it. That is why, when a new syntactic form appears, we will use it in a small problem and follow its result.
In the second part, we use the fundamental APIs and tackle activities that require more than one class: collections of data, files, communication, and concurrent work. Here the questions change: what does an API promise, who owns a resource, and what happens if two operations proceed together? These are situations in which a program can compile and still be wrong. The final part looks at code over time: quality, checks, maintenance, project tools, and static analysis. A teaching example that works today is only the first step; we also want to understand whether another programmer will be able to modify it tomorrow.
The boundary between the parts is not a wall. A good writing habit may appear in the very first program, and a language concept will return when we discuss maintenance. Cross-references indicate where a topic is developed in full, rather than leaving the explanation incomplete at the point where you need it. If a topic requires tools you do not yet know, I will point that out, and we will return to build it when we have the necessary bricks.
Three Ways to Read It
If Java is new to you, read the opening chapters in order and try to reproduce the examples before looking at the solutions. Pause at the Definition and Important note boxes: they often contain the detail that prevents a mistake in the following pages. You can leave the Further reading sections for a second reading.
If you already program in Java, use the contents and self-check activities to find the sections that put what you know to the test. An apparently elementary explanation may clarify an important distinction, such as the difference between a class and an object, or between compilation and execution. If a result surprises you, return to the example and check its behavior before moving on.
If you know Java from a few versions ago, look for the Java version boxes. They indicate when a capability became stable and, where necessary, why code shown in an old project may look different. The aim is not to turn the book into a list of releases: it is to reach the model of the language you will use now.
The three paths can cross. An experienced programmer may need to return to the distinction between a reference and an object; a beginner may be curious about an advanced box and read it without needing to master it immediately. Section labels make this freedom honest. When a chapter refers back to an earlier concept, the cross-reference must point to the right place; when a page anticipates something that will be explained later, it must say so and, meanwhile, offer enough context to continue. Skipping a section should not mean accepting an invisible gap.
Good practice – Read and try. Complete examples must have a corresponding source file in the book's materials. If you transcribe a fragment, check the filename, class name, package, and stated command. A typing mistake is normal; learning to read a compiler message is part of learning.
Conventions
Conventions are not there to decorate the page. They tell you what you are looking at and how much context you need to understand it. The following figure brings the main markers together, making each symbol’s purpose recognisable.
The legend places the section’s level beside its symbol, so its meaning remains understandable even in a black-and-white copy. Basics means that we are building a prerequisite and that it is worth reading carefully even if the topic seems simple. Further reading signals a more demanding passage, useful but postponable without interrupting the main path.
These markers may accompany a chapter title or an internal section. A chapter may begin with concepts for everyone and contain a further reading section later: the mark on the title gives an initial indication, while the one on the section is more precise. If an advanced marker is absent, readers should not infer that the topic is mysteriously more difficult; the text will follow the common path. Icons do not replace stated prerequisites: they indicate where to pause, not what can be known without an explanation.
Definition boxes establish the meaning of a term we will use again. Key concept boxes provide the mental model needed to follow a section. A Note may add context or a curiosity without interrupting the thread. A Java version box specifies the release and status to which a feature belongs. These labels are written out in full, so they remain understandable even if the book is read without colors or on a device that does not reproduce the icons well.
An Important note deserves particular attention: it usually highlights a point on which it is easy to build a mistaken idea. It is not an invitation to memorize an isolated exception, but to pause for a moment and check the model we have just used. Good practice is different: it proposes a concrete writing or design choice and explains the reason for it. A definition, finally, is not a typographic ornament; it is the agreement about the meaning of a word you will find again in the following pages.
Version markers distinguish what belongs stably to Java 25 from what is being tried out. When we state the version in which a feature was introduced, the number is not there to create a chronology to learn by heart. It helps explain why an example does not compile with an earlier JDK, or why two projects written in different years adopt different forms. If a capability is still preview or incubator, the box says so and gives the options needed to try it separately from the main path.
In the text, keywords, commands, filenames, classes, and packages are written as code: class, javac, Greeting.java, java.util. Italics distinguish the title of a work or a term we are introducing; bold highlights a decisive word in the explanation. A complete program is separated from the prose and has a precise filename. A fragment, by contrast, is identified as such: you should not expect it to compile on its own.
Figures representing classes and interfaces follow a simple rule too. An inheritance arrow goes from the more specific class toward the more general one; a use arrow indicates which element uses another object. When we encounter these relationships in the chapter on objects, we will interpret them together. Color helps distinguish the elements, but labels and arrows provide the meaning.
In technical figures, a class and an interface have distinguishable shapes or labels. “Extends” describes the relationship between a subclass and its base class, or between interfaces; “implements” connects a class to the contract of an interface; “uses” says that one element collaborates with another without declaring a type relationship. If we draw a class B that extends A, we are not saying that B physically contains a separate A object. If B implements interface A, we are not saying that it inherits another class's state. And if B uses A, we have not yet specified whether the relationship is temporary or retained in a field: the text beside the figure will explain that. Colors and orientation may vary to suit the page; names and captions must keep the meaning intact.
Important note – An example is not a universal prescription. In the opening chapters, some programs are deliberately small. They isolate an idea and may omit checks, error handling, or organization that would be necessary in a real application. I will point out these limitations, without presenting a teaching shortcut as a general good practice.
License of Use
This edition is distributed under the Creative Commons Attribution–NonCommercial 4.0 International license. Subject to the conditions stated in the official text, the license allows the material to be shared and adapted with attribution, with changes indicated, and without using it for commercial purposes. Other rights, such as those relating to third-party images, may require specific checks. To understand all the conditions and exceptions, you need to read the license rather than rely on this summary.
It is worth reading what the conditions mean, because an “open book” does not mean a book without rules. This license permits sharing the material and creating adaptations; anyone doing so must appropriately identify the author, link to the license, and make the changes recognizable. Attribution must not suggest that the author approves of how others use the text. The noncommercial condition limits uses primarily directed toward commercial advantage or payment. Nor may legal restrictions or technological measures be added that prevent others from making uses already permitted by the license.
There are also limitations that a reader might not expect. Parts already in the public domain and uses permitted by legal exceptions follow their own rules. The license provides no warranties and does not automatically settle third-party rights: a photograph, a trademark, the image of a person, or someone else's contribution may require separate checks. The official Creative Commons summary helps you find your way, while the legal text linked from that page contains the complete conditions. Any attribution and specific terms for third-party material must be considered alongside the volume’s license.
Sources
The first source for this book was the experience of programming, making mistakes, correcting them, and explaining. When I was writing the 2022 edition, I had twenty-six years of professional work as a programmer behind me. That count did not include the hours spent writing assembly language on the Commodore 64, or the experiments with C and Pascal on my Amiga 2000. I have worked with different languages in very different fields, from the military sector to telecommunications and enterprise systems. Each taught me something about the way a program is written, used, and then maintained by others. I encountered Java in 1996: to use the words with which I described it then, it was love at first sight.
This book’s method is to build an explanation step by step. Each example should help readers recognise a problem, follow a solution and put it to the test. A Java feature gains meaning when it answers a concrete need and connects to an idea already established. Remembering syntax is therefore not enough: we need to understand what it lets us express, which conditions it requires and where it ceases to be useful.
The official Java documentation is the reference for syntax, platform behavior, and APIs. The specifications describe the meaning of language constructs and virtual machine operations; library documentation tells users what a method promises. Consulting them is not merely a duty of precision: it helps distinguish what Java guarantees from what seems to happen in a single program or a particular implementation. When we encounter a delicate rule, I will first try to make it understandable through an example, and then indicate where to check its exact formulation.
Alongside the documentation, Oracle’s Java Magazine offers ideas, techniques and reflections on the language; Baeldung is a practical resource for exploring specific problems. These readings have helped shape the book’s path. An article can raise the right question or suggest an experiment; but if we are establishing what Java 25 guarantees, we return to the specification and the APIs for the relevant version. It is a way to use different sources without confusing an interesting idea with a language rule.
Finally, there are people. Programmer friends, colleagues, acquaintances, and readers have offered me advice, corrections, and interesting code fragments. Sometimes a question asked at the right moment is enough to reveal that an explanation taken to be clear is not clear at all. At other times, an error reported by someone who actually tries an example improves the page. We learn from anyone who has something to say. Let us not forget that when a solution already seems obvious to us.
Acknowledgments and a Small Apology
A special thank-you goes to Catia Niccolai, my partner in life and my colleague at work. She has closely followed the various versions of the book, putting up with the long stretches of time and the revisions a page involves, and has reread the drafts. It is work less visible than a cover, but anyone who has tried to finish a book knows how much a careful reading matters when the author can no longer see their own mistakes.
Finally, an apology in advance for an example or two that does not resemble a work problem. Sometimes a small, even slightly artificial situation lets us see a mechanism that a real application would hide among many details. When that happens, the reason will be stated. And as soon as the mechanism is clear, we will try to use it in a more credible context.
Check Your Understanding
Before starting the next chapter, try to answer without going back: what is the difference between a Basics section and a Further reading section? Where would you look for the status of an experimental feature? What do you check if a program copied from the book does not compile? The answers are in the conventions: recognizing them now will save you time as you read.
For a practical activity, prepare a working folder for the examples and note the version of the JDK you have installed by running java --version and javac --version in a terminal. Keep both outputs. The activity is complete when both commands are available and report a consistent version; if one of them is not found, the chapter on tools will explain how to distinguish a missing JDK from an execution path that has not been configured.