Part 0 · 2 chapters · ~12 min
Basics
Installing a JDK, compiling and running (including single-file source launch), classes, objects and packages, primitive and reference types, control flow, strings and text blocks, collections, var, exceptions, and the shape of a Maven or Gradle project.
1
From 1996 to modern Java
code
// Fees.java: run directly with `java Fees.java` (single-file source launch, Java 11+)
import java.util.List;
public class Fees {
static long fee(long amountKobo) {
if (amountKobo <= 0) throw new IllegalArgumentException("amount must be positive: " + amountKobo);
return Math.max(amountKobo * 50 / 10_000, 1_000);
}
public static void main(String[] args) {
var amounts = List.of(100_000L, 5_000_000L); // var: local type inference (Java 10+)
for (var a : amounts) System.out.printf("%,d kobo → fee %,d%n", a, fee(a));
String json = """
{"amount_kobo": 5000000, "currency": "NGN"}
"""; // text block (Java 15+)
}
}JAVA, THEN AND NOW
the releases that changed how Java is written
swipe the figure sideways, or tap expand for full screen
1/4
the promise
Java compiles to bytecode for the JVM, so the same .class files run on any platform. Garbage collection and a large standard library made it the enterprise default.
bytecode on a portable VMGC and a big standard library
2
Projects, collections and exceptions
code
# Gradle (Kotlin DSL) or Maven: the two build tools
./gradlew build ./mvnw package # wrappers pin the tool version in the repo
Map<String, Long> balances = new HashMap<>();
balances.merge("ada", 500_000L, Long::sum); // add or create
List<Long> big = transfers.stream().map(Transfer::amount).filter(a -> a > 10_000_000).toList();
try { ledger.post(entry); }
catch (InsufficientFundsException e) { return problem(422, e.getMessage()); } // checked or unchecked
finally { metrics.record(); }Money: use long minor units or BigDecimal with an explicit RoundingMode; never double. And never construct BigDecimal from a double (new BigDecimal(0.1) is 0.1000000000000000055…); use new BigDecimal("0.1").