1. Getting Started
This book is built around small Java programs that can be read in the browser
and run from a local development environment. The core examples target
JDK 25, the latest long-term support release, so the syntax stays current
without depending on preview language features.
1.1. Version baseline
Use JDK 25 for the main book examples. JDK 26 is the latest feature release, but JDK 25 is the better default for an introductory book because it is the current LTS release.
The main example project is in source/code and is configured with Maven.
Its pom.xml sets the compiler release to JDK 25 and does not enable preview
features.
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
Preview features are covered separately in the JDK 26 notes. Keep preview code out of the main examples unless the chapter explicitly says otherwise.
1.2. Running compact source files
JDK 25 can run a small Java file directly.
java hello.java
This is the easiest way to try the first chapter. It does not require a Maven project, a package declaration, or a separate compilation step.
1.3. Running with Docker
The Docker image from the preface starts Jupyter Lab on port 8888.
docker run -it \
-p 8888:8888 \
oneoffcoder/book-java-intro
Open http://localhost:8888 after the container is running. If the published
image lags behind the book’s JDK 25 baseline, use a local JDK 25 installation
for the newer language examples.
1.4. Running with Maven
From the main project directory, compile and test the Java examples with Maven.
cd source/code
mvn test
To run one class directly, compile first and then invoke the fully qualified class name.
cd source/code
mvn test
java -cp target/classes com.oneoffcoder.java.intro.HelloWorld
Examples that depend on external libraries, such as OpenCSV, are easiest to run
from Maven, Jupyter, or an IDE that understands the pom.xml file.
1.5. Reading examples in this book
Most chapters show only the lines that matter for the topic being discussed.
The complete source files are under source/code/src/main/java. For example,
the first class-based program appears in the book as a short listing, but the
full file is available at source/code/src/main/java/com/oneoffcoder/java/intro.
1package com.oneoffcoder.java.intro;
2
3public class HelloWorld {
4
5 public static void main(String[] args) {
6 System.out.println("Hello, world!");
7 }
8
9}
The package name at the top of a file must match its directory path under
src/main/java. That relationship becomes important as programs grow beyond
a single file.