ByteScrollGet the app
☰ Topics

bytescroll --learn java

Java interview prep, one card at a time.

Swipe through the most-asked Java interview questions. Every card has a short answer you can say out loud; tap Deep dive for examples, diagrams and the follow-up you'll get asked next.

Coming soon to the App StoreComing soon to Google Play

Try the free sample → · 20 questions free. All 200 with Pro — plus every subject we add.

JAVA / MODERN-JAVA3 minute read

Pattern matching for switch (Java 21)

Medium

Since Java 21, a case can test a type and bind it: case Circle c ->. Add a guard with when, take records apart with record patterns, and handle null with case null. Over a sealed type the compiler checks every subtype is covered, so no default is needed.

ExampleJava
sealed interface Shape permits Circle, Rect, Square {}
record Circle(double r) implements Shape {}
record Rect(double w, double h) implements Shape {}
record Square(double side) implements Shape {}

static String describe(Shape s) {
    return switch (s) {
        case null -> "nothing";
…
Deep dive →