So, you’ve got a Java interview coming up, and you haven’t touched Java since the Java 8 era when lambdas were the hot new thing? Or maybe you’re a Scala developer wondering what the JVM folks have been up to? Welcome, friend!
Let me be straight with you: this is a subjective list of topics that I think matter for modern Java interviews. Not everyone will agree with every item here, and that’s fine. Different companies care about different things. But if you can confidently discuss these topics and tackle the questions I’ve listed, you’ll walk into that interview room ready to impress.
This guide is organized into Basic, Medium, and Advanced sections, plus a special Bonus section that’ll make you practically unbreakable in your interview. Each topic links to a detailed blog post with code examples, and I’ve included the kinds of questions interviewers actually ask.
Basic Level - The Foundation
These are the must-know topics. If you’re shaky on any of these, the interviewer will notice. But don’t worry—we’ve got detailed posts for each one!
1. Immutable Data with Java Records
What It Is: Java finally got a concise way to create immutable data classes with records (Java 16+). Think Scala case classes, but for Java.
Read the full post: Immutable Data with Java Records
What You’ll Learn: The post covers the evolution from verbose Java 8 immutable classes to elegant records, including compact constructors for validation, auto-generated methods, and defensive copying. You’ll see side-by-side comparisons with Scala case classes and understand when records shine.
Interview Questions You Might Face:
- “How do you create an immutable data class in modern Java? Walk me through a record example.”
- “What’s the difference between a record and a traditional class with private final fields?”
- “Can you add custom methods to records? What about validation?”
- “How do records compare to Scala case classes or Kotlin data classes?”
- “When would you NOT use a record?”
2. String Manipulation with Modern APIs
What It Is: Java 11-17 brought powerful String methods that make text processing actually pleasant.
Read the full post: String Manipulation with Modern APIs
What You’ll Learn: This post shows how to process multi-line text using methods like isBlank(), lines(), strip(), indent(), and text blocks. You’ll see the evolution from painful Java 8 StringBuilder gymnastics to clean, fluent modern code.
Interview Questions You Might Face:
- “How would you process a multi-line string in modern Java?”
- “What’s the difference between
trim(),strip(),stripLeading(), andstripTrailing()?” - “Explain text blocks. When were they introduced and why are they useful?”
- “How do you split a string into lines without manually handling newline characters?”
3. Null-Safe Programming with Optional
What It Is: Stop writing if (thing != null) checks everywhere. Optional is Java’s answer to Scala’s Option type.
Read the full post: Null-Safe Programming with Optional
What You’ll Learn: The post demonstrates how to refactor nested null checks into elegant Optional chains using map(), flatMap(), filter(), and friends. You’ll learn the Java 9+ enhancements and see comparisons with Scala and Kotlin approaches.
Interview Questions You Might Face:
- “How do you handle potentially null values in modern Java?”
- “Explain the difference between
orElse()andorElseGet(). When does it matter?” - “What’s wrong with
Optional.get()? What should you use instead?” - “How do you chain multiple Optional operations together?”
- “What are some Optional anti-patterns to avoid?”
4. Collection Factory Methods and Stream Basics
What It Is: Java 9+ made creating and processing collections way less painful with factory methods and improved Stream APIs.
Read the full post: Collection Factory Methods and Stream Basics
What You’ll Learn: Learn how to use List.of(), Set.of(), Map.of() and process data with streams. The post covers filtering, grouping, statistics, and the difference between immutable and mutable collections.
Interview Questions You Might Face:
- “How do you create an immutable list in Java 9+?”
- “What happens if you try to add an element to a collection created with
List.of()?” - “Walk me through processing a collection: filter by condition, group by category, calculate statistics.”
- “What’s
Collectors.teeing()and when would you use it?” - “Explain the difference between
collect(Collectors.toList())andtoList().”
5. Local Variable Type Inference with var
What It Is: The var keyword (Java 10+) lets you skip explicit types for local variables. Use it wisely!
Read the full post: Local Variable Type Inference with var
What You’ll Learn: This post shows when var improves readability and when it makes code cryptic. You’ll learn the rules (where you can and can’t use it) and best practices for maintainable code.
Interview Questions You Might Face:
- “Explain Java’s
varkeyword. How does it differ from JavaScript’svaror Scala’svar?” - “Where can you use
varand where can’t you?” - “Give me an example where
varhurts readability.” - “Can you use
varfor method parameters or return types? Why or why not?” - “How does
varwork with generics and the diamond operator?”
Medium Level - Where It Gets Interesting
You know the basics. Now let’s talk about the features that separate “knows Java” from “knows modern Java.”
1. Sealed Classes and Exhaustive Pattern Matching
What It Is: Java 17’s sealed classes let you control inheritance and write exhaustive pattern matching. It’s like Scala’s sealed traits finally came to Java!
Read the full post: Sealed Classes and Exhaustive Pattern Matching
What You’ll Learn: Build a type-safe payment system using sealed classes and pattern matching. The post shows how to model domain logic with compiler-enforced exhaustiveness, using records for data and sealed interfaces for behavior.
Interview Questions You Might Face:
- “Explain sealed classes. Why would you use them?”
- “What’s the difference between
sealed,non-sealed, andfinalin this context?” - “How does Java’s pattern matching in switch differ from traditional switch statements?”
- “Show me how to model a payment system with different payment types using sealed classes.”
- “What’s exhaustive pattern matching and why does it matter?”
- “How do sealed classes in Java compare to Scala’s sealed traits?”
2. Functional Interfaces and Lambda Expressions
What It Is: Build reusable, composable code with Java’s functional programming features.
Read the full post: Functional Interfaces and Lambda Expressions
What You’ll Learn: This post builds a configurable retry mechanism from scratch, demonstrating custom functional interfaces, lambda expressions, method references, and function composition. You’ll see how Java’s functional features compare to Scala and Kotlin.
Interview Questions You Might Face:
- “What makes an interface a functional interface?”
- “Explain the standard functional interfaces: Function, Predicate, Consumer, Supplier.”
- “How do you handle checked exceptions in lambda expressions?”
- “What’s the difference between instance method references and static method references?”
- “Implement a retry mechanism using functional interfaces.”
- “How does Java’s approach to functions differ from Scala’s?”
3. CompletableFuture and Asynchronous Programming
What It Is: Write concurrent code that doesn’t block threads. CompletableFuture is Java’s answer to Scala Futures and Kotlin coroutines.
Read the full post: CompletableFuture and Asynchronous Programming
What You’ll Learn: The post shows how to aggregate data from multiple APIs concurrently with proper timeout handling, error recovery, and composition. You’ll learn thenApply(), thenCompose(), allOf(), and exception handling patterns.
Interview Questions You Might Face:
- “How do you run multiple operations concurrently in Java?”
- “Explain the difference between
thenApply()andthenCompose().” - “How do you handle timeouts in CompletableFuture?”
- “What’s the difference between
exceptionally()andhandle()?” - “How would you fetch data from three APIs concurrently and combine the results?”
- “How does CompletableFuture compare to Scala’s Future or Kotlin coroutines?”
4. Stream API Advanced Operations
What It Is: Beyond basic filtering and mapping—custom collectors, parallel streams, and complex data analysis.
Read the full post: Stream API Advanced Operations
What You’ll Learn: Analyze datasets with running totals, top-N queries, grouping with downstream collectors, and custom collectors. The post covers takeWhile(), dropWhile(), parallel streams, and performance considerations.
Interview Questions You Might Face:
- “How do you find the top N items per category using streams?”
- “Explain
Collectors.groupingBy()with downstream collectors.” - “What’s the difference between
takeWhile()andfilter()?” - “When should you use parallel streams? When should you avoid them?”
- “How do you create a custom collector?”
- “Walk me through calculating running totals with streams.”
Advanced Level - Java 21 Power Features
This is where you prove you’re not just up-to-date, but ahead of the curve. These are the Java 21 features that’ll make interviewers sit up and take notice.
1. Virtual Threads and Structured Concurrency
What It Is: Project Loom revolutionizes Java concurrency. Millions of lightweight threads that don’t eat your memory? Yes, please!
Read the full post: Virtual Threads and Structured Concurrency
What You’ll Learn: Migrate from thread pools to virtual threads, handle thousands of concurrent HTTP requests efficiently, and understand structured concurrency with StructuredTaskScope. The post includes comparisons with traditional threading and discusses when to use virtual vs platform threads.
Interview Questions You Might Face:
- “What are virtual threads and why do they matter?”
- “How do virtual threads differ from platform threads?”
- “Explain the thread-per-task model. Why is it viable now?”
- “What’s thread pinning and how do you avoid it?”
- “When would you still use platform threads instead of virtual threads?”
- “How do virtual threads compare to Kotlin coroutines?”
- “Walk me through migrating a thread-pool-based service to virtual threads.”
2. String Templates (Preview Feature)
What It Is: Safe string interpolation that prevents injection attacks. Finally, Java joins the cool kids with string interpolation!
Read the full post: String Templates Preview
What You’ll Learn: Build safe SQL queries using the STR and FMT processors, create custom template processors for domain-specific needs, and understand how this prevents injection vulnerabilities. Includes comparisons with Scala and Kotlin string interpolation.
Interview Questions You Might Face:
- “What are string templates in Java 21?”
- “How do string templates prevent SQL injection?”
- “Explain the difference between the
STRandFMTprocessors.” - “How would you create a custom template processor?”
- “Why are string templates better than concatenation or
String.format()?” - “This is a preview feature—what does that mean for production code?”
3. Foreign Function and Memory API (FFM)
What It Is: Call native C libraries without the pain of JNI. It’s like JNI went to therapy and came back a better person.
Read the full post: Foreign Function and Memory API
What You’ll Learn: Integrate with native libraries using the FFM API’s Arena memory management, MemorySegment for direct memory access, and Linker for native function calls. The post shows how this is safer and simpler than traditional JNI.
Interview Questions You Might Face:
- “How do you call native C functions from Java in modern Java?”
- “What’s the Foreign Function and Memory API?”
- “Explain Arena and why it matters for memory safety.”
- “How does FFM compare to JNI?”
- “What’s a MemorySegment and how do you use it?”
- “Give me a use case where you’d need to integrate with native code.”
Bonus: Tricky Java Patterns - Become Interview-Proof! 🛡️
Alright, you’ve got the fundamentals down, you know the new features, but there’s one more level. These are the gotchas, the quirks, the “why does it work that way?” patterns that separate people who use Java from people who understand Java.
Master these, and you’ll be absolutely unbreakable in your interview. When the interviewer throws you a curveball question about why something behaves unexpectedly, you’ll explain it like you wrote the JVM yourself.
Read the full post: Tricky Java Patterns That Everyone Uses
This post covers 8 confusing patterns with runnable examples. Here’s what you’re up against:
1. ArrayList.toArray() Optimization Surprise
The Question: “I see two ways to convert a List to an array: passing an empty array new String[0] or a sized array new String[list.size()]. Which is better and why?”
The Gotcha: Logic says pre-sizing should be faster, but modern JVMs optimize the empty array case better! It’s 15-20% faster due to escape analysis and stack allocation. Old StackOverflow answers (pre-Java 6) are wrong.
What You’ll Learn: Why counter-intuitive patterns exist, how JVM optimizations work, and that toArray(Type[]::new) is the modern best practice.
2. String Concatenation in Loops
The Question: “Why is string concatenation in a loop bad? Does it still matter in modern Java?”
The Gotcha: Each += creates a new String object, leading to O(n²) complexity. BUT—Java 9+ optimizes single-statement concatenation using invokedynamic. So it matters for loops, not for single statements.
What You’ll Learn: When StringBuilder is essential vs when the compiler handles it, and how to spot performance problems before they hit production.
3. Integer Caching: The == Trap
The Question: “Why does Integer a = 100; Integer b = 100; a == b return true, but the same with 200 returns false?”
The Gotcha: Java caches Integer objects from -128 to 127. The == operator checks object identity, not value. This causes subtle bugs because tests use small numbers, but production uses larger ones!
What You’ll Learn: Wrapper caching rules, why you should always use .equals() for wrapper types, and how this bites people in production.
4. Stream.of() vs Arrays.stream() for Primitive Arrays
The Question: “I’m calling Stream.of(intArray) but count() returns 1 instead of the array length. What’s wrong?”
The Gotcha: Stream.of(int[]) treats the array itself as one element! For primitive arrays, you must use Arrays.stream() or IntStream.of().
What You’ll Learn: Why primitive arrays behave differently from object arrays in streams, and the correct patterns for each type.
5. Double-Checked Locking Evolution
The Question: “Explain double-checked locking. Why does it need volatile in modern Java?”
The Gotcha: The new operator isn’t atomic—CPU can reorder instructions, causing other threads to see an uninitialized object! Pre-Java 5, double-checked locking was broken. Java 5+ fixed it with the volatile keyword.
What You’ll Learn: Memory model basics, why the holder pattern is better than double-checked locking, and how to write thread-safe lazy initialization.
6. Switch Expressions vs Statements
The Question: “What’s the difference between switch expressions and switch statements? When do I use yield vs return?”
The Gotcha: Arrow syntax (->) doesn’t fall through like colon syntax (:). Expressions must be exhaustive. You use yield to return from a block within a switch expression, never return (that would exit the method!).
What You’ll Learn: Pattern matching order matters, null handling in switch expressions (Java 21), and guarded patterns with when clauses.
7. Try-With-Resources Gotchas
The Question: “In what order do try-with-resources close resources? What happens to exceptions during close?”
The Gotcha: Resources close in reverse order (LIFO, like a stack). If both body and close throw exceptions, the body exception is primary, and close exceptions are suppressed (accessible via getSuppressed()). Without try-with-resources, close exceptions would hide body exceptions!
What You’ll Learn: Resource lifecycle management, suppressed exceptions, and common mistakes like returning a closed resource.
8. Virtual Thread Pinning (Java 21)
The Question: “What is thread pinning and why does it kill virtual thread performance?”
The Gotcha: Using synchronized with blocking I/O pins virtual threads to platform threads, destroying scalability. One synchronized block holding a long operation can exhaust your thread pool!
The Gotcha Solution: Use ReentrantLock instead of synchronized with virtual threads. The JVM can’t transfer monitor ownership, but it can transfer lock ownership.
What You’ll Learn: How to detect pinning with JVM flags, when to prefer ReentrantLock, and best practices for virtual thread-friendly code.
Why This Section Makes You Unbreakable
These aren’t academic puzzles—they’re real bugs that slip through code review and explode in production. When you can explain:
- Why empty arrays are faster for
toArray() - Why
Integer == Integerworks sometimes but not always - Why virtual threads need different locking patterns
…you demonstrate a level of understanding that most developers never reach. You’re not just writing Java; you’re thinking in Java.
The interviewer will probably say something like “Wow, most people don’t know that” at least twice. Trust me on this one.
Your Study Plan
Here’s how I’d approach this if I were you:
Week 1-2: Foundation Refresh
Work through the Basic topics. If you’re rusty on Java fundamentals, this is your safety net. Don’t skip it!
Week 3-4: Level Up
Tackle the Medium topics. This is where modern Java starts to feel different from Java 8. Take your time with sealed classes and pattern matching—they’re a mindset shift.
Week 5-6: The Good Stuff
Dive into Advanced topics. Virtual threads alone could fill a week. These are the features that’ll make you excited about Java again (if you ever were 😉).
Week 7: The Secret Weapon
Study the Bonus section thoroughly. Practice explaining each gotcha out loud. These are your interview super-power.
Week 8: Integration & Practice
Build something that combines multiple features. Mock interviews with a friend. Review anything that still feels shaky.
Additional Resources
- JEP Index for Java 21 - The official source
- Java Language Updates - Oracle docs
- Inside Java Blog - Straight from the Java team
- This Repository’s Code Examples - All the runnable code
Final Thoughts
Look, interviews are stressful. You might blank on a question you knew yesterday. That’s normal. But if you work through these topics, you’ll have something more valuable than memorized answers—you’ll have understanding.
When the interviewer asks “How would you solve X?”, you won’t be frantically searching your memory for the right pattern. You’ll think about the problem, consider the trade-offs, and propose a solution. That’s what senior developers do.
And hey, even if you don’t nail every question, you’ll walk out knowing you prepared well. The rest is just seeing if this job is the right fit for you too.
Good luck out there! You’ve got this. 🚀
P.S. - Found this guide helpful? Found something wrong? Have suggestions? Open an issue on the GitHub repo. Let’s make this resource better together.