« Previous
Next »
Summary
Wrapping up the Java track with what you can ship and where to go next.
What you learned + virtual thread example
EXAMPLE
# Java summary
You can now:
- Author modern Java with records, sealed types, pattern matching, text blocks
- Use streams + collectors + Optional fluently
- Apply virtual threads + structured concurrency for IO
- Build Spring Boot 3 services with minimal starters
- Persist with Spring Data JPA + Postgres + Testcontainers
- Observe with Micrometer + OpenTelemetry
- Containerise with multi-stage builds; non-root, pinned base
- Ship with GitHub Actions + OIDC
# Your next step - virtual threads + structured concurrency
import java.util.concurrent.StructuredTaskScope;
import java.net.http.*;
import java.net.URI;
record Page(String url, String body) {}
public class Fetcher {
public static void main(String[] args) throws Exception {
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
var a = scope.fork(() -> get('https://example.com/'));
var b = scope.fork(() -> get('https://example.org/'));
scope.join();
scope.throwIfFailed();
System.out.println(a.get().body().length() + b.get().body().length());
}
}
static Page get(String url) throws Exception {
var http = HttpClient.newHttpClient();
var req = HttpRequest.newBuilder(URI.create(url)).build();
var res = http.send(req, HttpResponse.BodyHandlers.ofString());
return new Page(url, res.body());
}
}
Why it matters
Modern Java is a different language than Java 8. Records, sealed types, virtual threads, and Testcontainers are the daily defaults. Pair with Spring Boot 3 + OTel + Docker and you have a production stack you can build a long career on.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
« Previous
Next »
Discussion
Loading…