Java

0%
Coding
Theory
Quiz

    Collections Framework

    • Explain the difference between 'Comparable' and 'Comparator'. When is each appropriate?

      Junior
    • What is the time complexity of searching in an ArrayList vs. a LinkedList? Why?

      Junior
    • What is the difference between HashMap and Hashtable?

      Junior
    • What is the difference between Iterator, ListIterator, and the Iterable interface?

      Junior
    • What is the difference between a fail-fast and a fail-safe iterator, and which collections use which and why?

      Mid
    • What are Sequenced Collections, and what problem do they solve in the existing Collections hierarchy?

      Mid
    • Why does ConcurrentHashMap not allow null keys or values, while HashMap does?

      Mid
    • What is the difference between 'fail-fast' and 'fail-safe' (non-blocking) iterators?

      Mid
    • When would you use a CopyOnWriteArrayList over a synchronized List?

      Mid
    • What problem do Sequenced Collections (introduced in Java 21) solve that the previous Collections hierarchy did not?

      Mid
    • How does a HashMap handle collisions internally in Java 8+, including the transition from Linked List to Balanced Tree?

      Mid
    • What is the difference between List.of() and Arrays.asList() regarding mutability and null handling?

      Mid
    • Explain the 'Fail-Fast' vs. 'Fail-Safe' iterator contract. Which collections use which?

      Mid
    • What gap in the Collections Framework did Java 21's SequencedCollection interface fill, and how does it unify the behavior of LinkedHashSet and ArrayList?

      Mid
    • How do TreeMap and TreeSet maintain ordering, and what is their time complexity for basic operations?

      Mid
    • What is a BlockingQueue, and how does it support the producer-consumer pattern?

      Mid
    • What is the difference between an immutable List created with List.of() and an unmodifiable view created with Collections.unmodifiableList()?

      Mid
    • How does a HashMap handle collisions in Java 8+? At what point does a linked list convert into a Red-Black Tree?

      Senior
    • How does a HashMap work internally in Java 8? Explain the transition from LinkedList to TreeNode.

      Senior
    • In what specific scenarios would a LinkedList actually outperform an ArrayList, considering modern CPU cache behavior?

      Senior
    • How does ConcurrentHashMap achieve thread safety, and how did its locking strategy change from segment locking to bucket-level CAS in Java 8?

      Senior

    Exceptions & Resource Handling

    • Explain the 'Try-with-Resources' statement. What interface must a class implement to be used within it?

      Junior
    • What is the difference between Checked and Unchecked Exceptions? Why is there a trend toward Unchecked?

      Mid
    • How does 'try-with-resources' work internally? What interface must the resource implement?

      Mid
    • What is the philosophical difference between a Checked and an Unchecked exception, and when should you create a custom Checked exception?

      Mid
    • Why does Java distinguish between Checked and Unchecked exceptions? What is the modern architectural trend regarding this distinction?

      Mid
    • What is the conceptual difference between a checked and an unchecked exception, and why is there a trend in modern Java libraries to favor RuntimeException?

      Mid
    • What is the difference between ClassNotFoundException and NoClassDefFoundError?

      Senior

    Oop Classes & Inheritance

    • What are the key methods defined on the Object class, and why are toString(), equals(), and hashCode() so important?

      Junior
    • What is the difference between an Interface and an Abstract Class in Java 17+ (considering default/private methods)?

      Mid
    • What is the 'Diamond Problem' in multiple inheritance, and how does Java solve it with Interfaces?

      Mid
    • With the introduction of default and static methods in interfaces, is there still a reason to use an abstract class?

      Mid
    • Explain the difference between 'Composition' and 'Inheritance.' Why is the industry moving toward 'Composition over Inheritance'?

      Mid
    • Why is 'composition over inheritance' a recommended practice in Java, and what are the risks of deep inheritance hierarchies in large-scale systems?

      Mid
    • What are the different types of nested classes in Java (static nested, inner, local, anonymous) and how do they differ?

      Mid
    • How are enums implemented in Java, and why is an enum considered the best way to implement a singleton?

      Mid

    Strings

    • What is the 'String Pool' and how does it help with memory management?

      Junior
    • What is the difference between String, StringBuilder, and StringBuffer, and when would you use each?

      Junior
    • Why are Strings immutable in Java? Mention security and performance reasons.

      Mid
    • Explain the 'String Templates' feature in Java 21. How does it improve security compared to simple string concatenation?

      Mid
    • Why are Strings immutable in Java? Explain the security and performance implications of the String Pool.

      Mid
    • Why is the String Pool critical for Java's memory management, and why was the decision made to keep Strings immutable?

      Mid

    Equality Immutability & Object Contracts

    • Explain the contract between 'equals()' and 'hashCode()'. What happens if you break it?

      Junior
    • What is the contract between hashCode() and equals(), and what happens if you override one but not the other?

      Junior
    • Why is it critical to override hashCode() whenever you override equals()? What happens in a HashSet if you don't?

      Junior
    • How do you make a class truly immutable in Java, and what are the benefits of immutability in a multithreaded environment?

      Mid
    • If you override equals(), why must you also override hashCode()? What happens if two unequal objects have the same hash code in a HashSet?

      Mid
    • What is the difference between a shallow copy and a deep copy, and what are the pitfalls of the Cloneable interface and Object.clone()?

      Mid

    Language Fundamentals & Types

    • Is Java 'Pass-by-Value' or 'Pass-by-Reference'? Explain with an example of an Object.

      Junior
    • Is Java pass-by-value or pass-by-reference? Explain what happens when you pass an object reference to a method.

      Junior
    • What is the difference between method overloading and method overriding, and how does static (compile-time) versus dynamic (runtime) binding apply to each?

      Junior
    • What is the difference between '==' and the 'equals()' method when comparing objects in Java?

      Junior
    • What does the 'static' keyword mean, and how do static initializer blocks and static fields get initialized when a class is loaded?

      Junior
    • What are the four access modifiers in Java (public, protected, default, private) and what visibility does each provide?

      Junior
    • What are varargs, and what are the rules and pitfalls when using them?

      Junior
    • What is autoboxing and unboxing, and why can comparing two Integer objects with '==' give surprising results due to the Integer cache?

      Mid
    • What is the difference between BigDecimal and double, and when should you avoid floating-point types for calculations?

      Mid

    Functional Programming & Streams

    • What is a Functional Interface? Can you name three built-in ones in the JDK?

      Junior
    • Explain the difference between 'Intermediate' and 'Terminal' operations in the Stream API.

      Junior
    • What is the purpose of 'Optional'? Does it prevent NullPointerExceptions entirely?

      Junior
    • What is a 'Method Reference' and how does it relate to Lambda expressions?

      Junior
    • What makes an interface a 'Functional Interface', and can you have multiple methods in it if they are default or static?

      Junior
    • What makes an interface a 'Functional Interface'? Can a functional interface have multiple methods such as default or static methods?

      Junior
    • Are Java Streams 'lazy'? What does that mean for performance?

      Mid
    • Explain the difference between intermediate and terminal operations in the Stream API, and why are Streams considered 'lazy'?

      Mid
    • What is the primary purpose of the Optional class, and why is it generally discouraged to use Optional as a method parameter or a class field?

      Mid
    • What are the tradeoffs of using Java Streams? In what specific scenarios would a traditional for loop be more performant?

      Mid
    • Explain the 'lazy evaluation' of Java Streams. Why won't an intermediate operation like filter() execute until a terminal operation is called?

      Mid
    • Why is it considered a 'code smell' to use Optional.get() without isPresent()? When should you use Optional as a return type versus a method parameter?

      Mid
    • How do Collectors work in the Stream API, and how would you use groupingBy or partitioningBy?

      Mid
    • What is the difference between map() and flatMap() in the Stream API?

      Mid
    • Why must local variables captured by a lambda or anonymous class be final or effectively final?

      Mid
    • What are the risks of using parallelStream(), and how does it interact with the common ForkJoinPool?

      Senior
    • When is it actually detrimental to use .parallelStream(), and how does the underlying ForkJoinPool affect the performance of other parts of the application?

      Senior

    Records Sealed Classes & Pattern Matching

    • How do Java Records differ from standard POJOs, and why are they considered 'transparent carriers' of data?

      Mid
    • Explain Pattern Matching for switch. How does it improve upon the traditional switch statement?

      Mid
    • What is the purpose of 'Unnamed Patterns and Variables' in Java 21?

      Mid
    • What is the purpose of a sealed class, and how does it improve the security or maintainability of a class hierarchy?

      Mid
    • What are Java Records, and why are they considered more than just 'syntactic sugar' for POJOs?

      Mid
    • Explain how Pattern Matching for switch and instanceof changes the way we handle complex conditional logic.

      Mid
    • Why are Records considered 'transparent carriers' of data, and how does this differ from a standard class?

      Mid
    • Explain 'Pattern Matching for switch.' How does it change the way we handle complex object hierarchies?

      Mid
    • Why should you use a Record instead of a standard class for a DTO, and what are the implications for inheritance and immutability?

      Mid
    • Explain how 'Pattern Matching for switch' changes the way we handle complex object hierarchies compared to the instanceof check.

      Mid
    • What is the 'Closed World Assumption' introduced by Sealed Classes, and why is it useful for the compiler?

      Senior
    • What is the 'Algebraic Data Type' (ADT) pattern in Java, and how do Sealed Classes and Records work together to implement it?

      Senior
    • What is the architectural benefit of using sealed classes and interfaces, and how do they improve the reliability of switch pattern matching?

      Senior

    Concurrency Fundamentals & Memory Model

    • Explain the different states of a Java thread and what causes a thread to move from Runnable to Waiting.

      Junior
    • What does the 'volatile' keyword actually guarantee regarding visibility and instruction reordering?

      Mid
    • What is the difference between 'synchronized' and 'ReentrantLock'? When would you prefer the latter?

      Mid
    • How does a 'Deadlock' occur, and what are the four necessary conditions for it?

      Mid
    • What is the difference between the volatile keyword and Atomic variables, and why doesn't volatile guarantee atomicity?

      Mid
    • When would you use ReentrantLock instead of a synchronized block, and what are the trade-offs in terms of fairness and flexibility?

      Mid
    • How do wait(), notify(), and notifyAll() work, and why must they be called from within a synchronized block?

      Mid
    • What is a daemon thread, and how does it differ from a user thread in terms of JVM shutdown?

      Mid
    • Explain the Java Memory Model (JMM) and the 'happens-before' relationship.

      Senior
    • What is the 'happens-before' relationship in the Java Memory Model, and why is it critical for thread safety?

      Senior
    • Explain the Java Memory Model (JMM). Why is it possible for a thread to see a partially initialized object?

      Senior
    • What is 'False Sharing' in a multithreaded Java application, and how does the @Contended annotation address it?

      Senior
    • Explain the 'happens-before' relationship. Why does volatile solve visibility issues but not atomicity issues?

      Senior
    • When would you use StampedLock over ReentrantReadWriteLock, and what are the tradeoffs of optimistic reading?

      Senior
    • How do atomic classes like AtomicInteger work, and what is Compare-And-Swap (CAS)?

      Senior

    Memory Stack Heap & Leaks

    • What is the difference between the Stack and the Heap? What specifically is stored in each?

      Junior
    • Explain the 'Metaspace' in Java 8+. How does it differ from the old PermGen?

      Mid
    • How can a memory leak occur in a Java application despite having an automatic Garbage Collector?

      Mid
    • How would you identify a memory leak in a Java application if the Heap usage is constantly growing?

      Senior
    • What is 'Escape Analysis' and how does it allow the JVM to perform scalar replacement?

      Senior
    • Why can an OutOfMemoryError occur even if the heap has plenty of free space?

      Senior
    • What is the 'Double Brace Initialization' anti-pattern, and why does it cause memory leaks?

      Senior
    • What is Metaspace, and how does its management of class metadata differ from the old PermGen model? Why does it cause OutOfMemoryError differently?

      Senior
    • Walk me through what happens in memory when you call new ArrayList(). Where is the object header stored, and how does the JVM track its age for GC?

      Senior
    • Why are primitives stored on the stack while objects are on the heap? How does 'Escape Analysis' allow the JVM to sometimes allocate objects on the stack?

      Senior

    Garbage Collection

    • What is the 'Stop-the-World' phase in GC, and how do modern collectors try to minimize it?

      Mid
    • Explain the concept of Generational Garbage Collection. Why is the heap divided into Young and Old generations?

      Mid
    • What is the difference between Minor, Major, and Full Garbage Collection, and what triggers a 'Stop-the-World' event?

      Mid
    • Explain the difference between the G1 Garbage Collector and the ZGC (Z Garbage Collector).

      Senior
    • What is the difference between the G1 and ZGC garbage collectors, and when would you prefer one over the other for a low-latency application?

      Senior
    • How does the ZGC (Z Garbage Collector) achieve sub-millisecond pause times even with terabyte-sized heaps?

      Senior
    • What are the primary differences between the G1 Garbage Collector and the ZGC, and in what scenario would you choose ZGC over G1?

      Senior

    Generics

    • What is Type Erasure in Java Generics, and what limitations does it impose on developers at runtime?

      Mid
    • What is 'Type Erasure' in Generics? Why can't you use primitives as type parameters?

      Mid
    • Explain the PECS (Producer Extends, Consumer Super) principle. When would you use <? extends T> versus <? super T>?

      Mid
    • What is 'Type Erasure' in Java Generics? What are its limitations?

      Senior
    • Explain the PECS (Producer Extends, Consumer Super) rule in Generics.

      Senior
    • What is Type Erasure in Java Generics? Why can't you use primitives as type parameters, and how does 'Project Valhalla' aim to solve this?

      Senior

    Executors Futures & Synchronizers

    • Explain the difference between 'submit()' and 'execute()' in an ExecutorService.

      Mid
    • What is the difference between Future and CompletableFuture, and what limitations of Future does CompletableFuture address?

      Mid
    • How should you properly shut down an ExecutorService, and what is the difference between shutdown() and shutdownNow()?

      Mid
    • How does 'CompletableFuture' handle exception propagation in an asynchronous pipeline?

      Senior
    • What is the 'Fork/Join' framework, and how does 'work-stealing' help in load balancing?

      Senior
    • What is the difference between CountDownLatch, CyclicBarrier, and Semaphore, and when would you use each?

      Senior

    Virtual Threads & Structured Concurrency

    • What are Virtual Threads (Project Loom) and how do they differ from traditional Platform Threads?

      Mid
    • What are Virtual Threads, and how do they differ from traditional Platform Threads in terms of resource management?

      Mid
    • What is the fundamental difference between a Platform Thread and a Virtual Thread?

      Mid
    • When would you still prefer a fixed thread pool over virtual threads?

      Mid
    • What is the fundamental difference between a platform thread and a virtual thread in terms of how they are mapped to the OS?

      Mid
    • Explain the concept of 'Thread Pinning' in the context of Virtual Threads. When does it happen?

      Senior
    • Why can't you use 'synchronized' blocks effectively with Virtual Threads in certain scenarios?

      Senior
    • When would you choose Virtual Threads over a reactive programming model (like CompletableFuture or Flux)?

      Senior
    • Explain the concept of 'Carrier Thread Pinning.' In what scenarios does a virtual thread fail to unmount from its carrier?

      Senior
    • Why would you choose Scoped Values over ThreadLocal in a system using millions of virtual threads?

      Senior
    • What is 'Structured Concurrency' and how does it prevent thread leaks compared to the traditional ExecutorService?

      Senior
    • Explain the concept of 'mounting' and 'unmounting' a virtual thread. What happens to the carrier thread when a virtual thread performs a blocking I/O operation?

      Senior
    • What is 'thread pinning' in the context of Virtual Threads, and why does using the synchronized keyword potentially cause performance issues in a virtual thread environment?

      Senior
    • How does Structured Concurrency improve the observability and reliability of multi-threaded tasks compared to using ExecutorService?

      Senior
    • Why were Scoped Values introduced in Java 21, and what are the memory and scalability tradeoffs compared to using ThreadLocal?

      Senior

    Jvm Platform & Execution

    • What is the difference between the JDK, the JRE, and the JVM?

      Junior
    • Explain the role of the Bootstrap, Extension, and Application ClassLoaders.

      Mid
    • How does the JIT (Just-In-Time) compiler decide when to compile a method into native code?

      Senior
    • Explain the role of the JIT compiler. How does it optimize code at runtime compared to the initial bytecode interpretation?

      Senior
    • What is 'Class Data Sharing' (CDS) and how does it improve the startup time of Java microservices in containers?

      Senior
    • How does the JIT compiler decide when to move code from C1 to C2 (Tiered Compilation)?

      Senior
    • Explain how the JIT compiler decides to move code from Level 1 to Level 4 (C2) compilation. What is 'code cache' exhaustion?

      Senior
    • What is the Java Platform Module System (JPMS) introduced in Java 9, and what problems does it solve?

      Senior

    Reflection Serialization & Annotations

    • What is 'Reflection' and what are the performance and security risks of using it?

      Mid
    • What is 'Serialization' and what is the role of 'serialVersionUID'?

      Mid
    • What are 'Annotations' and how are they processed at runtime vs. compile time?

      Mid
    • Why is standard Java Serialization often considered a security risk, and what are the modern alternatives for object persistence?

      Senior

    References & Thread Locals

    • Explain the 'final', 'finally', and 'finalize' keywords. Why is 'finalize' deprecated?

      Junior
    • Explain the 'Strong vs. Weak vs. Soft' reference types. When would you use a WeakHashMap?

      Mid
    • What is a 'ThreadLocal' variable, and what is the risk of using it in a thread-pooled environment?

      Senior
    • Explain the difference between 'Strong', 'Soft', 'Weak', and 'Phantom' references.

      Senior