Java: From a Working Environment to Object-Oriented Design

Java is one of those languages that is easy to start with and easy to keep using badly. The syntax is small enough to read in an afternoon, and the standard library is large enough that almost every task has a reasonable answer somewhere inside it, which is exactly why so much Java in the wild looks like three frameworks stapled together with a build script. This course takes the opposite path. It starts from an empty directory and an empty terminal, and it builds up the mental model that the rest of the language depends on, one working step at a time, so that the code you write later is a consequence of decisions you understand rather than a template you copied.

The course exists to solve a specific problem: that the gap between “I know programming” and “I can work in a Java codebase” is wider than it should be, and that most of the width comes from tooling rather than from the language. Very few Java beginners lose their way over generics. They lose their way over the fact that a compiler, a virtual machine and a build tool are three independent programs that can each be a different version, over the class path, over the difference between a package name and a directory, or over whether a given method will actually be dispatched at runtime. Those are learnable facts, they are checkable facts, and they are the facts this course is built around.

The material is in three parts, and the parts are meant to be read in order. The first part is the environment: what a JDK actually contains, how the compiler, the runtime and the build tool relate to each other, which distribution and which version to choose, how JAVA_HOME and PATH have to be set for all of them to agree, and how a Maven or Gradle project is laid out on disk. The second part is the first program: writing a class, compiling it, running it, and then taking apart every stage of that pipeline, including the parts that are invisible when everything works, such as what the compiler produced, where the class file went, how the launcher found the entry point, and why the class path is the single most common cause of a mysterious failure. The third part is the object model: classes and objects, fields and constructors, access control, inheritance, polymorphism, interfaces, abstract classes, records, enums, sealed types, generics, the equality contract, and the collections framework.

The order is not arbitrary, and each part assumes the previous one. Nothing about a build tool can be evaluated before you know that a class file is produced by a compiler and consumed by a virtual machine, because a build tool is exactly a program that chains those two steps and manages the files between them. Nothing about packages, imports or the class path can be understood before you have seen a class file appear on disk and been told which directory has to be on the class path for it to be found. And nothing about inheritance or polymorphism can be judged before the reader knows what a class is and what an object is, because those are the words the whole object model is written in. Reading the chapters out of order is possible, but each one will refer back to something that has not been established yet, and the references will feel arbitrary rather than natural.

The prerequisites are modest. You should already be comfortable with the basic syntax of some other programming language: variables, conditionals, loops, functions and the idea of a data structure. You do not need any Java at all, because the course starts by installing it. You do need to be willing to use a terminal, because most of what is taught here is verified by running a command and reading what it prints, and a build that “should work” teaches nothing. It helps to have seen a build tool before, whether Maven, Gradle, npm, cargo or anything else, but it is not required: the environment chapter explains the build tools from the beginning rather than assuming them. A reader who has never used a package manager will lose a little time in the first chapter and gain it back in the third.

Two conventions hold throughout. Every command and every version is current rather than historical, and the Java examples target Java 21, with Java 17 called out where the difference matters, because those are the two long-term releases most projects are actually built on today. Every code sample is meant to be run: the programs in the first program chapter are complete, they compile, and they print what the surrounding text says they print. Where a snippet is a fragment rather than a whole file, it is short enough to paste into one, and where a fragment cannot be run on its own, the text says so. The point of the convention is that a reader can always tell the difference between a claim about Java and a claim about an example, and can check the second kind for themselves.

The course is deliberately narrow. It stops at the object model, and it does not try to cover the collections framework in depth, concurrency, the module system, persistence frameworks or any web stack. That is not a limitation of the material but the boundary of it, and it is drawn where it is because the object model is the part that everything else assumes: the collections are containers that a domain model fills, the concurrency story is about sharing objects safely, and every framework you will later use is a large set of classes organised with exactly the techniques taught in the third chapter. If you take the three chapters in order and finish the exercises at the end of each one, you will be able to read an ordinary Java class and say what every modifier does, predict which implementation a call will actually reach, and know why a build failed before you have to search for it.

Each chapter closes with a worked reference answer that is written out in full: the reasoning that leads to the solution, the individual steps with the commands or the code in the order they are executed, and the final result together with the evidence that shows the work succeeded. Those answers are meant to be read after you have attempted the exercise, because the value of a reference solution is largest when it can be compared against your own attempt, and the differences between the two are where the remaining misunderstanding usually is. They also work as a second reading of the chapter: the steps restate the commands in an order that a beginner would not have guessed, which is often the clearest description of the workflow the chapter was trying to teach.

There is a way of working through this material that is much more effective than reading it. Keep a terminal open next to the text, and run every command as you meet it rather than assuming it will behave as described. The examples are short enough that running them costs little, and the failures are informative: a command that does not work usually shows a message that is itself part of the lesson, such as the class path error in the second chapter or the constructor error in the third. Writing the examples out by hand rather than copying them is slower and worth it, because the mistakes you make while typing are the ones you will remember the fix for.

It is also worth saying plainly who this course is not for. It is not a route to a framework: there is no Spring, no Android, no web framework, and no database in it, because each of those is a large subject that assumes the material covered here. It is not a reference for the Java standard library either, and it is not a guide to performance, to concurrency or to the module system. What it is for is the first stretch of the road, where the language is still unfamiliar and the toolchain is still unexplained, and where a reader who gets those two right will find everything that comes afterwards considerably easier to evaluate.

By the end you will have a reproducible Java environment that you can rebuild on a new machine from memory, a working understanding of the compile-and-run pipeline that explains most Java error messages on sight, and an object model that you can apply to a problem of your own. You will also have the habits that make the rest of the language learnable: verify the toolchain before trusting it, read the actual error instead of the remembered one, and keep the state of an object behind methods that are allowed to protect its invariants. Those habits are what separate someone who has written Java from someone who can maintain Java.

javafundamentals

Approach:

The course is organised around a dependency chain rather than around a feature list. A reader cannot debug a build before the build tool exists, cannot use a build tool before the compile-and-run cycle makes sense, and cannot design a class hierarchy before knowing what a class is. Each chapter therefore produces an artefact that the next chapter consumes: a verified toolchain, a running program with a known pipeline, and an object model with rules for state, visibility, extension and equality. The teaching moves from the concrete and observable to the abstract, and every stage ends with something the reader can run rather than merely believe.

Steps:

  1. Establish the environment first, because it is the only part of the course that touches the machine outside the editor. Install a JDK rather than a runtime, verify the compiler and the runtime with java -version and javac -version, point JAVA_HOME at the JDK root and PATH at its bin directory, and confirm that Maven or Gradle runs on the same version as the shell.
  2. Build a project skeleton and understand what it contains: the standard source layout, the pom.xml or the build script, the difference between the output directory and the source directory, and the fact that the build tool is a program that chains the compiler and the runtime.
  3. Write the first program and follow it end to end, from source file to class file to running process. Learn what the compiler produced, where the class file went, and that the launcher looks for exactly one entry point signature.
  4. Take the pipeline apart where it usually breaks: the class path, the relationship between a package name and a directory, the difference between an import and a load, and the exact wording of the compile-time and runtime errors that appear when each piece is wrong.
  5. Cover input and output, because almost every small program needs them: reading from standard input with Scanner without tripping over the newline trap, and writing with printf and the format specifiers.
  6. Move to the object model as the natural next layer: state in fields, behaviour in methods, construction through constructors that chain, and visibility chosen deliberately for each member.
  7. Then the extension mechanisms in the order they compose: inheritance and overriding, dynamic dispatch, interfaces with default methods, abstract classes, and the specialised forms that modern Java added, namely records, enums and sealed types.
  8. Finish with the rules that keep a codebase coherent: the equality contract, the meaning of final and static in each position, generics and what erasure implies, and the collections framework behind its interfaces.

Answer:

A reader who completes this course can answer four questions about any Java program they open. Which tools produced it, and do they agree on a version? What does the compiler emit, and where does the runtime look for it? Which method actually runs when a call appears to be polymorphic? And which rules does each class follow about state, visibility and equality?

The first question is answered by the environment: a JDK with a matching compiler and runtime, JAVA_HOME and PATH pointing at the same installation, and a build tool running on that same version. The second is answered by the class path and the package layout, which is why the second chapter spends its time on the compile-and-run pipeline rather than on syntax. The third is answered by the rules of dispatch: overridden instance methods dispatch dynamically, static methods are hidden, and final methods and private methods cannot be overridden at all. The fourth is answered by the declarations themselves: private fields behind validating methods, final identity fields, constructors that chain, equals and hashCode overridden together, and sealed hierarchies that say who may extend them.

Those four answers are what a working Java developer uses every day, and they are the reason the course is ordered the way it is.

Found an issue with this content?

Tell us what could be improved.