Engineering Course

Java Interview
Mastery 2026.

Java remains the bedrock of enterprise engineering. With the arrival of Java 21 LTS and Virtual Threads, the ecosystem has undergone a massive shift toward high-throughput, low-latency architectures. This guide provides the high-signal knowledge required for senior engineering roles.

In the modern landscape, being a "Java Developer" requires a deep understanding of the Java Virtual Machine (JVM) internals. Since the release of Java 17 and 21, the focus has shifted from simple object-oriented patterns to modern concurrency models and cloud-native optimizations. Developers must now master how the Garbage Collector (G1, ZGC) impacts application latency and how GraalVM can be used to optimize cloud infrastructure costs.

This course covers the full spectrum of a technical interview: from core memory management and garbage collection strategies to the latest Spring Boot 3 features. We explore how Virtual Threads (Project Loom) have largely replaced the need for complex reactive programming in many use cases, allowing for massive scalability while maintaining code readability.

1The Primacy of POO (OOP) Principles

Explain the difference between Abstraction and Polymorphism.

Abstraction is about hiding complexity and showing only the necessary details to the user (the 'What'). Polymorphism is about the ability of an object to take on many forms, allowing different classes to be treated as instances of the same parent class through method overriding (the 'How').

How does Java 21's Records feature impact Encapsulation?

Records provide a concise way to create data-carrier classes with built-in encapsulation. By default, fields are private and final, and the compiler generates accessors, ensuring that the state remains immutable and protected from unintended modifications.

What is the 'Liskov Substitution Principle' and why is it critical?

Part of the SOLID principles, it states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. Breaking this leads to fragile code that requires constant type-checking.

2SOLID & Design Patterns

Explain the Dependency Inversion Principle (DIP).

DIP states that high-level modules should not depend on low-level modules; both should depend on abstractions. Using Interfaces for service definitions allows you to swap implementations (e.g., changing a database provider) without touching the service consumers.

Singleton Pattern: How do you implement it for thread safety?

Modern Java uses the 'Initialization-on-demand holder idiom' or an 'Enum Singleton'. These approaches leverage the JVM's class-loading mechanism to ensure the instance is created lazily and is inherently thread-safe without explicit synchronization overhead.

When would you choose a Factory Pattern over a Constructor?

Factories are useful when the creation logic is complex, involves multiple steps, or when you need to return different subclasses based on input parameters. They decouple the client code from the specific implementation being instantiated.

3JVM Internals & Memory Management

Explain the Java Memory Model (Stack vs. Heap) in modern JVMs.

The Stack handles thread-local execution (method frames and primitive variables), while the Heap manages global object allocation. Modern JVMs use generational garbage collection, dividing the heap into Young and Old generations to optimize for object longevity.

What is ZGC (Z Garbage Collector) and why does it matter?

ZGC is a scalable, low-latency garbage collector introduced to handle massive heaps (up to 16TB) with sub-millisecond pause times. It performs most of its work concurrently with application threads, making it ideal for high-performance enterprise systems.

How do Virtual Threads (Project Loom) change Java concurrency?

Virtual threads are lightweight, JVM-managed threads that remove the one-to-one mapping with OS threads. This allows developers to write synchronous, blocking code that scales to millions of concurrent tasks, drastically simplifying reactive-style programming.

4Advanced Core Java 21+

What are the most impactful features in Java 21 LTS?

Java 21 introduced Record Patterns for cleaner data extraction, Sequenced Collections for predictable ordering, and full support for Virtual Threads. It represent a significant modernization of the language's core syntax and performance profile.

Explain Pattern Matching for switch expressions.

Pattern matching allows a 'switch' to test against types and extract data from objects in one step. It reduces boilerplate code and enhances type safety, making Java code more expressive and less prone to 'instanceof' checks.

What is a 'sealed' class and why use it?

Sealed classes and interfaces restrict which other classes may extend or implement them. This allows developers to define closed-hierarchy domain models, which is crucial for secure library design and exhaustive pattern matching in switches.

5Spring Boot 3 & Cloud Native

What are the benefits of GraalVM Native Images in Spring Boot 3?

GraalVM allows compiling Spring applications into standalone executables (Native Images). These have significantly faster startup times (milliseconds vs seconds) and lower memory footprints, making them perfect for serverless and containerized environments.

Explain the difference between @RestController and @Controller.

@RestController is a specialized version of @Controller that includes @ResponseBody. It simplifies API development by automatically serializing return objects into JSON or XML for the HTTP response body.

How does Spring Boot handle Dependency Injection internally?

Spring uses an IoC (Inversion of Control) container that scans for components, manages their lifecycle, and injects dependencies via constructors or setters. Constructor injection is the recommended standard as it ensures required dependencies are present at instantiation.

6Recruiter's Screening Room (Junior & Confirmed)

What is the primary difference between '==' and '.equals()'?

The '==' operator compares memory references (identity), checking if both objects point to the same location. The '.equals()' method compares the actual content/values of the objects (equality) based on the class implementation.

Explain the difference between String, StringBuilder, and StringBuffer.

String is immutable (cannot be changed). StringBuilder is mutable and faster but not thread-safe. StringBuffer is mutable and thread-safe (synchronized) but slightly slower than StringBuilder.

What do 'final', 'finally', and 'finalize' mean?

'final' is a keyword to make a variable/method/class unchangeable. 'finally' is a block used in exception handling that always executes. 'finalize' is a method called by the Garbage Collector before an object is destroyed (deprecated in newer Java versions).

When should you use ArrayList vs. LinkedList?

Use ArrayList for frequent data retrieval (O(1) access). Use LinkedList for frequent insertions or deletions at the beginning or middle of the list (O(1) insertion) as it doesn't require shifting elements.

What is the difference between Checked and Unchecked exceptions?

Checked exceptions are checked at compile-time (e.g., IOException) and must be handled or declared. Unchecked exceptions are checked at runtime (e.g., NullPointerException) and usually indicate programming errors.

7Microservices & Cloud Native Architecture

Explain the Saga Pattern and how to handle distributed transactions.

Distributed transactions (2PC) are hard to scale. The Saga pattern breaks a transaction into a series of local transactions. If one fails, it triggers 'Compensating Transactions' to undo previous steps, ensuring 'Eventual Consistency' across services without locking resources.

What is 'Observability' in 2026 and how does OpenTelemetry help?

Observability goes beyond simple logging. It includes Metrics, Traces, and Logs (the three pillars). OpenTelemetry provides a standardized API to instrument Java apps, allowing you to trace a request across multiple microservices to identify bottlenecks or failures instantly.

When should you use a Service Mesh (e.g., Istio) versus Spring Cloud Netflix?

Spring Cloud Netflix (Eureka/Ribbon) implements logic at the application layer. A Service Mesh like Istio handles traffic management, security, and observability at the infrastructure layer (sidecar pattern). Choose a Service Mesh for polyglot environments or when you need zero-trust security without modifying app code.

Advanced Insight: Project Loom

One of the most significant shifts in Java history is the introduction of Virtual Threads. Unlike traditional platform threads that map 1:1 to OS threads, virtual threads are managed by the JVM. This allows an application to handle millions of concurrent tasks with minimal memory overhead.

// Modern Concurrency with Virtual Threads

try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
    IntStream.range(0, 10_000).forEach(i -> {
        executor.submit(() -> {
            Thread.sleep(Duration.ofSeconds(1));
            return i;
        });
    });
} // Executor auto-closes, waiting for all tasks

In this example, we start 10,000 threads simultaneously. In traditional Java, this would likely crash the system or cause severe context-switching lag. With Project Loom, this is a lightweight operation, enabling a "Thread-per-request" model even at massive scale.

Master the JVM.

Technical excellence at Kodivio is about more than just syntaxβ€”it's about understanding the underlying systems. Validate your Spring Boot API response payloads locally with our JSON Validator.