join() blocks the calling thread until the target thread has terminated, so any state the worker wrote is safely visible afterwards. Without it you could read the result before the worker ever set it.
int[] result = new int[1];
Thread worker = new Thread(() -> result[0] = 6 * 7);
worker.start();
worker.join();
System.out.println("Answer: " + result[0]);
Answer: 42
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27