Java’s Epic Transformation: From “Scoped Values” to “Project Loom” — A Hilarious Ride Through…
Interview 2025: A Look at Modern Java (21 to 25)
Java’s Epic Transformation: From “Scoped Values” to “Project Loom” — A Hilarious Ride Through Versions 21–25!
Interview 2025: A Look at Modern Java (21 to 25)
Interview Pointers (Easy Recall)
- Java 21 → Pattern Matching
- Java 22 → Scoped Values
- Java 23 → Structured Concurrency
- Java 24 → Virtual Threads & Vector API
- Java 25 → Project Loom + Project Amber
🙏 Stay Connected!
Follow my blog for tips and insights to crack your next interview!
I appreciate you taking the time to read my article. If you found it helpful, check out my other stories! 👉 Follow me on Medium 🚀
Follow my Java 8 playlist, where I’ve written a number of blogs to help you crack your next interview
👉 Also See Crack Your Next Java Interview: Essential Core Java Questions & Answers
👉 Also See Top Spring Boot and Microservices Interview Questions: No Question Beyond This
👉 Also See : Follow my Java 8 playlist, where I’ve written a number of blogs to help you crack your next interview: [Java 8 Playlist on Medium](https://medium.com/@saannjaay/list/java8-686652482e6b)
👉 Also See : [Java Interview Playbook: Your Go-To Reading List](https://medium.com/@saannjaay/list/java-interview-playbook-your-goto-reading-list-573a88c31215)
Java 21 — Pattern Matching for Switch
Java 21 introduced Pattern Matching for Switch, making switch expressions more powerful and type-safe.
It shows a magical machine with funnels for different types of data — like an Integer or a String. Instead of complex code, you just drop the data in, and the machine automatically processes it according to its type and gives you the correct, formatted output. The old, messy pile of junk next to a trash can labeled “Old If-Else” contrasts the new feature, showing how it simplifies and cleans up your code.

Pattern Matching for Switch
static String formatObject(Object obj) {
return switch (obj) {
case Integer i -> "Integer: " + i;
case String s -> "String: " + s.toUpperCase();
case null -> "Null value";
default -> "Unknown type";
};
}
public static void main(String[] args) {
System.out.println(formatObject(10)); // Integer: 10
System.out.println(formatObject("java")); // String: JAVA
}
Java 22 — Scoped Values
Java 22 introduced Scoped Values, a safer alternative to ThreadLocal. They allow you to share data within a scope of execution across threads, especially useful with Virtual Threads.
A secret agent, representing ScopedValue, creates a transparent "scope bubble". Inside this bubble, a special value ("Secret Value") is accessible to all the people (threads or methods) within that scope.
People outside the bubble are unable to access the value, no matter how hard they try. This perfectly visualizes how ScopedValue shares data securely and immutably only within a defined scope of execution, preventing it from being leaked or misused elsewhere.

import jdk.incubator.concurrent.ScopedValue;
public class ScopedValueExample {
static final ScopedValue<String> USER = ScopedValue.newInstance();
public static void main(String[] args) {
ScopedValue.where(USER, "Sanjay").run(() -> {
System.out.println("Hello, " + USER.get());
});
}
}
Java 23 — Structured Concurrency API
Java 23 added Structured Concurrency, making concurrent programming simpler and more reliable. It treats tasks running in different threads as a single unit of work.
The **StructuredTaskScope** in the code is the "conductor." It ensures that all the tasks (forked threads) are treated as a single unit of work.
- The
**scope.join()** method is like the conductor waiting for all the musicians to finish their part before ending the performance. - The
**scope.throwIfFailed()** method is the conductor's "Cancel" button. If one musician (like the clown with the smoking tuba) fails or messes up, the conductor can stop the entire performance gracefully, preventing "zombie threads" and ensuring the application doesn't get stuck in a bad state.

Java 23 — Structured Concurrency API
import java.util.concurrent.*;
public class StructuredConcurrencyDemo {
public static void main(String[] args) throws Exception {
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Future<String> user = scope.fork(() -> fetchUser());
Future<String> orders = scope.fork(() -> fetchOrders());
scope.join(); // Wait for both
scope.throwIfFailed(); // Handle exceptions
System.out.println(user.resultNow() + " -> " + orders.resultNow());
}
}
static String fetchUser() { return "User: Sanjay"; }
static String fetchOrders() { return "Orders: 5"; }
}
Java 24 — Virtual Threads & Vector API
Java 24 continued building on Virtual Threads (Project Loom) and introduced enhancements like the Vector API for performance.
public class VirtualThreadDemo {
public static void main(String[] args) throws InterruptedException {
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 10; i++) {
int taskId = i;
executor.submit(() -> {
Thread.sleep(100);
System.out.println("Task " + taskId + " done by " + Thread.currentThread());
return null;
});
}
}
}
}
Virtual Threads allow millions of lightweight threads, making concurrency scalable.
Vector API Example:
import jdk.incubator.vector.*;
public class VectorAPIDemo {
public static void main(String[] args) {
var a = FloatVector.fromArray(FloatVector.SPECIES_128, new float[]{1,2,3,4}, 0);
var b = FloatVector.fromArray(FloatVector.SPECIES_128, new float[]{5,6,7,8}, 0);
var c = a.add(b);
c.intoArray(new float[4], 0);
System.out.println(c); // [6.0, 8.0, 10.0, 12.0]
}
}
Java 25 — Project Loom & Project Amber
By Java 25, features like Project Loom and Project Amber are reaching maturity, giving Java developers a supercharged toolkit.
- Project Loom → Massive scalability with Virtual Threads & Structured Concurrency.
- Project Amber → Simplifying language features like records, pattern matching, and sealed classes.

Java 25 — Project Loom & Project Amber
Example combining Records + Pattern Matching + Virtual Threads:
record User(String name, int age) {}
public class Java25Demo {
public static void main(String[] args) throws Exception {
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
executor.submit(() -> {
User user = new User("Sanjay", 30);
System.out.println(switch (user) {
case User(String name, int age) when age > 18 -> "Adult: " + name;
default -> "Minor";
});
return null;
});
}
}
}
🙏 Stay Connected!
Follow my blog for tips and insights to crack your next interview!
I appreciate you taking the time to read my article. If you found it helpful, check out my other stories! 👉 Follow me on Medium 🚀
메타데이터
- post_id
- b5bb3a20b6f5
- slug
- javas-epic-transformation-from-scoped-values-to-project-loom-a-hilarious-ride-through-b5bb3a20b6f5
- url
- https://medium.com/@sanjaysingh-dev/javas-epic-transformation-from-scoped-values-to-project-loom-a-hilarious-ride-through-b5bb3a20b6f5
- canonical_url
- https://medium.com/@sanjaysingh-dev/javas-epic-transformation-from-scoped-values-to-project-loom-a-hilarious-ride-through-b5bb3a20b6f5
- author_url
- https://medium.com/@sanjaysingh-dev
- status
- ok
- fetched_at
- 2026-07-17 10:32:35