Lesson content
Read, practise, then check your understanding
Favor immutable values, small cohesive APIs, constructor-established invariants, composition, dependency injection, and standard abstractions. Validate at trust boundaries, close resources, avoid global mutable state, and never log secrets.
Measure before changing
static double average(int[] values) {
if (values.length == 0) return 0;
long sum = 0;
for (int value : values) sum = Math.addExact(sum, value);
return (double) sum / values.length;
}
Automate formatting, static analysis, unit/integration tests, dependency scanning, and observability. Profile representative workloads with tools such as Java Flight Recorder; algorithm, allocation rate, data locality, I/O, contention, and database access usually matter more than micro-syntax. Benchmark with JMH so JIT warmup and dead-code elimination are handled. Set a supported Java baseline and document performance changes with reproducible evidence.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.