Java interview questions
287 questions tagged by difficulty. Sign up to unlock full answers and track your weak areas.
- View
Differentiate between JDK, JRE, JVM.
Easy · Java, Core Java, JVM
- View
Why is Java called platform-independent?
Easy · Java, Core Java, JVM
- View
What is a classloader in Java? Explain its hierarchy (Bootstrap, Extension, Application).
Medium · Java, Core Java, JVM
- View
Differentiate between instance variable, class variable, and local variable.
Easy · Java, Core Java
- View
Difference between == and .equals(). When should each be used?
Easy · Java, Core Java
- View
Difference between String, StringBuilder, StringBuffer. Which one to use in multi-threaded scenarios?
Easy · Java, Core Java, Strings
- View
Why are Strings immutable in Java? Explain design reasons.
Easy · Java, Core Java, Strings
- View
What is String interning? How does it improve performance?
Medium · Java, Core Java, Strings
- View
Differentiate between final, finally, finalize.
Easy · Java, Core Java
- View
Differentiate between checked and unchecked exceptions. Provide examples.
Easy · Java, Core Java, Exception Handling
- View
Difference between throw and throws keywords.
Easy · Java, Core Java, Exception Handling
- View
What is try-with-resources? Why is it preferred over finally for closing resources?
Medium · Java, Core Java, Exception Handling
- View
What is autoboxing and unboxing in Java? Provide examples.
Easy · Java, Core Java
- View
Differentiate between primitive types and wrapper classes.
Easy · Java, Core Java
- View
Can we make main() method final, static, synchronized, or overloaded?
Easy · Java, Core Java
- View
How do annotations work in Java? How do you create custom annotations?
Medium · Java, Core Java
- View
Differentiate between reflection and introspection.
Hard · Java, Core Java
- View
How does dynamic class loading work in Java?
Hard · Java, Core Java, JVM
- View
What is the role of Class.forName()?
Medium · Java, Core Java, JVM
- View
What is the transient keyword? Why use it?
Easy · Java, Core Java
- View
Difference between Serialization and Externalization.
Medium · Java, Core Java
- View
How do you design an immutable class? Best practices?
Medium · Java, Core Java
- View
Is Java pass-by-value or pass-by-reference? Explain with examples.
Easy · Java, Core Java
- View
Differentiate between static initializer blocks and instance initializer blocks.
Easy · Java, Core Java
- View
What are enums in Java? Can enums have methods, constructors, and fields? Provide examples.
Medium · Java, Core Java
- View
What are EnumSet and EnumMap? Why are they more efficient than HashSet/HashMap for enums?
Medium · Java, Core Java, Collections
- View
What are varargs in Java? What are the rules and pitfalls when using them?
Easy · Java, Core Java
- View
Differentiate between static nested class, inner class, local class, and anonymous class.
Medium · Java, Core Java, OOP
- View
What are generics in Java? Explain type erasure and why it was introduced.
Medium · Java, Core Java
- View
Explain bounded wildcards in generics: <? extends T> vs <? super T>. What is the PECS principle?
Hard · Java, Core Java
- View
What are covariance and contravariance in Java generics? Why is List<Dog> not a List<Animal>?
Hard · Java, Core Java
- View
What is ThreadLocal? When and why should you use it? What are its pitfalls?
Medium · Java, Core Java, Concurrency
- View
Difference between Thread.sleep() and Object.wait(). When to use which?
Easy · Java, Core Java, Concurrency
- View
Difference between notify() and notifyAll(). When is each appropriate?
Medium · Java, Core Java, Concurrency
- View
What is the volatile keyword in Java? How does it ensure visibility without atomicity?
Medium · Java, Core Java, Concurrency
- View
Why is volatile necessary in double-checked locking for Singleton?
Hard · Java, Core Java, Concurrency
- View
What are the four pillars of OOP (Encapsulation, Inheritance, Polymorphism, Abstraction)? Explain each with real-world examples.
Easy · Java, OOP
- View
Difference between abstraction and encapsulation.
Easy · Java, OOP
- View
Explain encapsulation with a practical code snippet.
Easy · Java, OOP, Encapsulation
- View
Define coupling and cohesion in OOPs. Why is low coupling and high cohesion desirable?
Medium · Java, OOP, Design Principles
- View
Differentiate between HAS-A and IS-A relationships with examples.
Easy · Java, OOP, Inheritance
- View
Differentiate between composition and aggregation. Which is preferred and why?
Medium · Java, OOP, Design Principles
- View
Difference between deep copy and shallow copy.
Medium · Java, OOP
- View
Differentiate between clone() and copy constructor.
Medium · Java, OOP
- View
Differentiate between Abstract Class and Interface. When should you use which?
Medium · Java, OOP
- View
Can an abstract class have a constructor? Why?
Easy · Java, OOP
- View
What is a marker interface? Give examples (e.g., Serializable, Cloneable).
Easy · Java, OOP, Interfaces
- View
Can an interface have default and static methods (Java 8+ feature)? Provide use cases.
Medium · Java, OOP, Interfaces
- View
What are default and static methods in interfaces? Why were they introduced?
Easy · Java, OOP, Interfaces
- View
Can an interface extend multiple interfaces?
Easy · Java, OOP, Interfaces
- View
Explain multiple inheritance in Java and how Java resolves conflicts.
Medium · Java, OOP, Interfaces
- View
Why doesn't Java support multiple inheritance with classes?
Medium · Java, OOP
- View
Why does Java support single inheritance for classes but multiple inheritance for interfaces?
Medium · Java, OOP, Interfaces
- View
Explain the diamond problem. How Java 8 resolved it with default methods?
Hard · Java, OOP, Interfaces
- View
What happens if two interfaces define the same default method?
Hard · Java, OOP, Interfaces
- View
Differentiate between method overloading and method overriding with examples.
Easy · Java, OOP, Polymorphism
- View
What are the rules of method overriding (return type, access modifiers, exceptions)?
Medium · Java, OOP, Polymorphism
- View
Can we override private, static, or final methods? Why or why not?
Medium · Java, OOP, Polymorphism
- View
What is dynamic method dispatch in Java? Provide an example.
Medium · Java, OOP, Polymorphism
- View
Differentiate between compile-time polymorphism and runtime polymorphism.
Easy · Java, OOP, Polymorphism
- View
Provide a real-world example of polymorphism in Java.
Easy · Java, OOP, Polymorphism
- View
Can a constructor be overridden? Why or why not?
Easy · Java, OOP
- View
What is object slicing in OOPs?
Medium · Java, OOP
- View
Difference between deep inheritance vs shallow inheritance.
Medium · Java, OOP
- View
What are the commonly overridden methods from Object class (equals, hashCode, toString, clone)? How do you override them correctly?
Medium · Java, OOP
- View
Explain SOLID, DRY, KISS, YAGNI principles in Java OOP design.
Medium · Java, OOP, Design Principles
- View
Which functional programming principles did Java 8 adopt?
Medium · Java, Java 8+, Lambda
- View
What are Lambda expressions? Provide syntax and real-world examples.
Easy · Java, Java 8+, Lambda
- View
What are functional interfaces? Provide examples (Runnable, Supplier, Consumer, Function).
Easy · Java, Java 8+, Lambda
- View
Differentiate between Predicate, Function, Consumer, Supplier.
Medium · Java, Java 8+, Lambda
- View
What are method references? What are their types?
Easy · Java, Java 8+, Lambda
- View
Difference between stream() and parallelStream(). When to use which?
Medium · Java, Java 8+, Streams
- View
Differentiate between intermediate and terminal stream operations with examples.
Medium · Java, Java 8+, Streams
- View
Explain the difference between map(), flatMap(), filter(), reduce() in Streams.
Medium · Java, Java 8+, Streams
- View
Difference between flatMap in Streams vs Optional.
Medium · Java, Java 8+, Streams
- View
How does collect() work? Explain common collectors (toList, toSet, joining, groupingBy, partitioningBy).
Medium · Java, Java 8+, Streams
- View
Explain Collectors.groupingBy() and Collectors.partitioningBy() with examples.
Medium · Java, Java 8+, Streams
- View
Difference between findFirst() and findAny().
Easy · Java, Java 8+, Streams
- View
Difference between forEach() and forEachOrdered().
Easy · Java, Java 8+, Streams
- View
Can a stream be reused? Why not?
Easy · Java, Java 8+, Streams
- View
Difference between peek() and map().
Easy · Java, Java 8+, Streams
- View
What is a short-circuiting operation in streams? Examples.
Medium · Java, Java 8+, Streams
- View
What is a Spliterator? How is it different from Iterator?
Hard · Java, Java 8+, Streams
- View
Difference between reduce() and collect().
Medium · Java, Java 8+, Streams
- View
When should we use parallelStream()? What are the risks?
Hard · Java, Java 8+, Streams
- View
How does stream pipeline execution work internally?
Hard · Java, Java 8+, Streams
- View
Difference between mapMulti() (Java 16) and flatMap().
Hard · Java, Java 8+, Streams
- View
What is Optional in Java? How does it help avoid NullPointerException?
Easy · Java, Java 8+
- View
Difference between Optional.of(), Optional.ofNullable(), Optional.empty().
Easy · Java, Java 8+
- View
How do you safely retrieve a nested object's field using Optional?
Medium · Java, Java 8+
- View
How do you return a default value if null using orElse() and orElseGet()?
Easy · Java, Java 8+
- View
How do you throw an exception if a value is not present using orElseThrow()?
Easy · Java, Java 8+
- View
What is the difference between map() and flatMap() in Optional?
Medium · Java, Java 8+
- View
What are the best practices when using Optional in APIs?
Medium · Java, Java 8+
- View
Differentiate between LocalDate, LocalTime, LocalDateTime, ZonedDateTime.
Easy · Java, Java 8+, Date & Time
- View
Compare Date/Calendar API with java.time API. Why is the new API better?
Medium · Java, Java 8+, Date & Time
- View
Difference between List, Set, Map.
Easy · Java, Collections
- View
Difference between ArrayList and LinkedList.
Easy · Java, Collections
- View
Difference between HashSet, LinkedHashSet, TreeSet.
Easy · Java, Collections
- View
Difference between HashMap, LinkedHashMap, TreeMap.
Easy · Java, Collections
- View
Difference between HashMap and Hashtable.
Easy · Java, Collections, Concurrency
- View
What happens internally when HashMap.put() is called?
Easy · Java, Collections
- View
How does HashMap work internally? (hashCode, equals, buckets, rehashing, load factor).
Hard · Java, Collections
- View
How does LinkedHashMap maintain insertion order?
Medium · Java, Collections
- View
What is the time complexity of TreeMap for put()/get()?
Easy · Java, Collections
- View
Difference between Comparable and Comparator.
Easy · Java, Collections
- View
Differentiate between fail-fast and fail-safe iterators.
Medium · Java, Collections
- View
Differentiate between Enumeration, Iterator, and ListIterator.
Easy · Java, Collections
- View
What is a PriorityQueue and how does it work internally?
Medium · Java, Collections
- View
What is an IdentityHashMap? Where is it used?
Hard · Java, Collections
- View
How are WeakHashMap and SoftReference used in caching?
Hard · Java, Collections, JVM
- View
What is a ConcurrentSkipListMap and when would you use it?
Hard · Java, Collections, Concurrency
- View
How does ConcurrentHashMap handle collisions?
Hard · Java, Collections, Concurrency
- View
What are Immutable Collections in Java 9+?
Easy · Java, Collections
- View
Why is hashCode() important in collections?
Medium · Java, Collections
- View
Why must equals() and hashCode() be consistent?
Medium · Java, Collections
- View
What happens if you override equals() without overriding hashCode()?
Medium · Java, Collections
- View
Compare the thread-safety of StringBuffer vs StringBuilder.
Easy · Java, Concurrency, Core Java
- View
What is the copy-on-write mechanism?
Medium · Java, Concurrency
- View
Difference between synchronized and ReentrantLock.
Hard · Java, Concurrency
- View
What is a ReadWriteLock? When should you use it?
Medium · Java, Concurrency
- View
What is the difference between StampedLock and ReentrantReadWriteLock?
Hard · Java, Concurrency
- View
Can two threads access different synchronized methods on the same object simultaneously?
Medium · Java, Concurrency
- View
How do you detect and resolve deadlocks in Java?
Hard · Java, Concurrency
- View
What is the difference between livelock and starvation?
Medium · Java, Concurrency
- View
What is the difference between ConcurrentHashMap and SynchronizedMap?
Medium · Java, Collections, Concurrency
- View
How does ConcurrentHashMap achieve thread safety internally?
Hard · Java, Collections, Concurrency
- View
What is the difference between BlockingQueue and ConcurrentLinkedQueue?
Medium · Java, Collections, Concurrency
- View
Explain the producer-consumer problem using BlockingQueue.
Medium · Java, Collections, Concurrency
- View
What is the difference between CopyOnWriteArrayList and ArrayList?
Medium · Java, Collections, Concurrency
- View
How does ConcurrentSkipListMap ensure thread safety?
Hard · Java, Collections, Concurrency
- View
What is the ForkJoin framework? Provide a use case.
Hard · Java, Concurrency
- View
What are Phaser and Exchanger in Java concurrency utilities?
Hard · Java, Concurrency
- View
What is ThreadPoolExecutor? Explain its parameters.
Hard · Java, Concurrency
- View
Difference between newFixedThreadPool(), newCachedThreadPool(), and newSingleThreadExecutor().
Medium · Java, Concurrency
- View
What is backpressure in concurrent systems?
Hard · Java, Concurrency
- View
What happens if you submit too many tasks to a thread pool?
Medium · Java, Concurrency
- View
How do you implement a rate limiter in Java?
Hard · Java, Concurrency
- View
Explain the difference between thenApply() and thenCompose() in CompletableFuture.
Hard · Java, Concurrency, Java 8+
- View
Explain JVM Architecture (ClassLoader, Method Area, Heap, Stack, Native Method Area, PC Registers).
Medium · Java, Memory & JVM, JVM
- View
Differentiate between stack memory and heap memory.
Easy · Java, Memory & JVM
- View
Difference between OutOfMemoryError and StackOverflowError.
Easy · Java, Memory & JVM, JVM
- View
What is garbage collection? How does it work?
Medium · Java, Memory & JVM, JVM
- View
What are GC algorithms (Serial, Parallel, CMS, G1)?
Hard · Java, Memory & JVM, JVM
- View
Compare G1, ZGC, and Shenandoah garbage collectors.
Hard · Java, Memory & JVM, JVM
- View
What are stop-the-world events in GC?
Medium · Java, Memory & JVM, JVM
- View
Explain strong, weak, soft, and phantom references with use cases.
Hard · Java, Memory & JVM, JVM
- View
Differentiate between weak references and phantom references.
Hard · Java, Memory & JVM, JVM
- View
Differentiate between JIT compiler and interpreter.
Medium · Java, Memory & JVM, JVM
- View
What is escape analysis in JVM optimizations?
Hard · Java, Memory & JVM, JVM
- View
What is Metaspace (Java 8+) vs PermGen (Java 7-)?
Medium · Java, Memory & JVM, JVM
- View
Tools to monitor JVM memory (jconsole, jvisualvm).
Easy · Java, Memory & JVM, JVM
- View
How do you detect and fix memory leaks in Java?
Hard · Java, Memory & JVM, JVM
- View
Difference between compile-time constants (final static) and runtime constants.
Medium · Java, Tricky, Core Java
- View
Why must HashMap keys be immutable? What goes wrong if they are mutable?
Medium · Java, Tricky, Collections
- View
Why is String commonly used as a key in HashMap?
Easy · Java, Tricky, Collections
- View
What happens if hashCode() is not overridden properly?
Medium · Java, Tricky, Collections
- View
Difference between ConcurrentModificationException and IllegalStateException.
Medium · Java, Tricky, Collections
- View
What is the impact of load factor tuning in HashMap?
Hard · Java, Tricky, Collections
- View
When to prefer LinkedList over ArrayList?
Medium · Java, Tricky, Collections
- View
Real-world cases where CopyOnWriteArrayList is preferred?
Medium · Java, Tricky, Collections
- View
How to handle large datasets efficiently with Streams?
Hard · Java, Tricky, Streams
- View
When should we not use parallel streams?
Medium · Java, Tricky, Streams
- View
Can a Stream run infinitely? How do you handle it?
Medium · Java, Tricky, Streams
- View
Why prefer CompletableFuture over Thread or Executor?
Medium · Java, Tricky, Concurrency
- View
What are the pitfalls of using Optional as a field in entities?
Hard · Java, Tricky, Java 8+
- View
How to debug a thread deadlock in a production JVM?
Hard · Java, Tricky, Concurrency
- View
What is the Java Memory Model (JMM)? Explain happens-before relationship.
Hard · Java, Advanced Java, Concurrency
- View
How do AtomicInteger, AtomicLong, and AtomicReference work internally? What is CAS (Compare-And-Swap)?
Hard · Java, Advanced Java, Concurrency
- View
Differentiate between CountDownLatch, CyclicBarrier, and Semaphore with use cases.
Hard · Java, Advanced Java, Concurrency
- View
What is false sharing in CPU caches? How does it impact Java concurrent applications?
Hard · Java, Advanced Java, Concurrency
- View
What is lock-free programming? How does it improve concurrency compared to synchronized blocks?
Hard · Java, Advanced Java, Concurrency
- View
Classify the 23 GoF design patterns (Creational, Structural, Behavioral). Give two examples from each.
Medium · Java, Advanced Java, Design Patterns
- View
Implement Singleton using: Eager Loading, Lazy Loading, Bill Pugh, Enum, and Double-Checked Locking. Compare pros/cons.
Hard · Java, Advanced Java, Design Patterns
- View
Differentiate between Factory Method and Abstract Factory patterns. When to use which?
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Builder pattern. Why is it preferred over telescoping constructors?
Easy · Java, Advanced Java, Design Patterns
- View
Explain the Strategy pattern. How does Java 8 simplify it with lambdas?
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Observer pattern. How is it implemented in Java? How does it relate to event listeners?
Medium · Java, Advanced Java, Design Patterns
- View
Differentiate between Decorator and Proxy patterns. Provide real-world examples.
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Template Method pattern. Where is it used in Java frameworks (e.g., JdbcTemplate)?
Medium · Java, Advanced Java, Design Patterns
- View
Differentiate between Adapter and Facade patterns with Java examples.
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Chain of Responsibility pattern. Where is it used in Java (servlet filters, logging)?
Medium · Java, Advanced Java, Design Patterns
- View
Explain CompletableFuture chaining: thenApply, thenAccept, thenRun, handle, exceptionally.
Hard · Java, Advanced Java, Concurrency
- View
Difference between Future and CompletableFuture. What limitations does Future have?
Medium · Java, Advanced Java, Concurrency
- View
What are method handles (java.lang.invoke)? How do they differ from reflection?
Hard · Java, Advanced Java, JVM
- View
How does invokedynamic work under the hood? How are Java lambdas compiled?
Hard · Java, Advanced Java, JVM
- View
What is off-heap memory in Java? When and why would you use it?
Hard · Java, Advanced Java, Memory & JVM
- View
What are the major features introduced in Java 17 LTS?
Easy · Java, Java 17+
- View
What are the major features introduced in Java 21 LTS (virtual threads, sequenced collections, record patterns)?
Easy · Java, Java 17+
- View
What are Records in Java 16+? How do they differ from regular POJOs? What are their limitations?
Easy · Java, Java 17+
- View
What is a compact constructor in a Java Record? When would you use it?
Medium · Java, Java 17+
- View
What are Sealed Classes in Java 17? What problem do they solve? How do they work with pattern matching?
Medium · Java, Java 17+
- View
What are Sealed Interfaces? How do they enable exhaustive type hierarchies?
Medium · Java, Java 17+
- View
What is Pattern Matching for instanceof (Java 16)? How does it reduce boilerplate?
Easy · Java, Java 17+
- View
What is Pattern Matching for Switch (Java 21)? How do guard patterns work?
Medium · Java, Java 17+
- View
What are Record Patterns (Java 21)? How do they enable deconstruction in pattern matching?
Medium · Java, Java 17+
- View
What are Switch Expressions (Java 14)? How do they differ from switch statements? Explain arrow syntax and yield.
Easy · Java, Java 17+
- View
What are Text Blocks (Java 15)? How do they handle indentation and escape sequences?
Easy · Java, Java 17+
- View
What are Virtual Threads (Project Loom, Java 21)? How do they differ from platform threads?
Hard · Java, Java 17+, Concurrency
- View
How do virtual threads compare to reactive programming (WebFlux)? When would you choose one over the other?
Hard · Java, Java 17+, Concurrency
- View
What is Structured Concurrency (Java 21)? How does it simplify concurrent task management?
Hard · Java, Java 17+, Concurrency
- View
What are Sequenced Collections (Java 21)? What interfaces were introduced and why?
Easy · Java, Java 17+, Collections
- View
What are unnamed patterns and variables (Java 21)? How does the underscore _ work in pattern matching?
Medium · Java, Java 17+
- View
What is the Foreign Function & Memory API (Java 22)? How does it replace JNI?
Hard · Java, Java 17+, Advanced Java
- View
What are Scoped Values (Java 21)? How do they differ from ThreadLocal?
Hard · Java, Java 17+, Concurrency
- View
How do Java Records compare to Lombok @Value? What are the trade-offs?
Medium · Java, Java 17+
- View
How do Sealed Classes + Pattern Matching together enable Algebraic Data Types (ADTs) in Java?
Hard · Java, Java 17+
- View
Explain the Java Exception hierarchy. What is the difference between Error and Exception?
Easy · Java, Core Java, Exception Handling
- View
What is multi-catch exception handling (Java 7)? What are its benefits?
Easy · Java, Core Java, Exception Handling
- View
What is the execution order of try-catch-finally? What if both catch and finally throw exceptions?
Medium · Java, Core Java, Exception Handling
- View
How does the Iterable interface work? How does for-each loop use it internally?
Easy · Java, Core Java, Collections
- View
What is the difference between ArrayList and Arrays.asList()? What are the pitfalls of Arrays.asList()?
Medium · Java, Core Java, Collections
- View
Differentiate between Collections.unmodifiableList(), List.of(), and Collections.singletonList().
Medium · Java, Core Java, Collections
- View
What is the @FunctionalInterface annotation? What happens if you add a second abstract method?
Easy · Java, Core Java, Java 8+
- View
Why is string concatenation using + in a loop inefficient? How does the compiler optimize it?
Easy · Java, Core Java, Strings
- View
What is the String pool? How does String.intern() work? What are the memory implications?
Medium · Java, Core Java, Strings
- View
Can we catch Error in Java? Should we? When might catching OutOfMemoryError be justified?
Medium · Java, Core Java, Exception Handling
- View
After Java 8 default methods, when should you prefer an abstract class over an interface?
Medium · Java, OOP, Java 8+
- View
What is the diamond operator <> introduced in Java 7? How does it support type inference?
Easy · Java, Core Java
- View
What is the difference between a synchronized method and a synchronized block? Which is preferred?
Medium · Java, Concurrency
- View
What is an intrinsic lock (monitor) in Java? How does it relate to synchronized?
Medium · Java, Concurrency
- View
What is Thread.interrupt()? How do you correctly handle interruption in long-running tasks?
Medium · Java, Concurrency
- View
What are daemon threads in Java? How do they differ from user threads?
Easy · Java, Concurrency
- View
Difference between Callable and Runnable. When would you prefer Callable?
Easy · Java, Concurrency
- View
What is the difference between ExecutorService.submit() and execute()? What does submit() return?
Medium · Java, Concurrency
- View
What is the difference between CompletableFuture.allOf() and anyOf()? Provide use cases.
Medium · Java, Concurrency, Java 8+
- View
What is thread contention? How do you detect and reduce it in a Java application?
Hard · Java, Concurrency
- View
Why is Deque preferred over Stack in Java? What implementations does Deque have?
Easy · Java, Collections
- View
What is the NavigableMap interface? What methods does it add over SortedMap?
Medium · Java, Collections
- View
What is a BitSet in Java? When is it more memory-efficient than a boolean array?
Medium · Java, Collections
- View
How and when does a HashMap resize? What is rehashing and what is its time complexity?
Hard · Java, Collections
- View
Explain the Composite pattern. Where is it used in Java (e.g., file systems, UI trees)?
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Flyweight pattern. How does Java String pool use it?
Medium · Java, Advanced Java, Design Patterns
- View
Explain the State pattern. How does it differ from Strategy? Provide a real-world Java example.
Medium · Java, Advanced Java, Design Patterns
- View
Explain the Iterator pattern. How is it implemented in the Java Collections Framework?
Easy · Java, Advanced Java, Design Patterns
- View
Explain the Command pattern. How can Java 8 lambdas simplify its implementation?
Medium · Java, Advanced Java, Design Patterns
- View
What is var (local variable type inference, Java 10)? What are its rules and limitations?
Easy · Java, Java 17+
- View
What are enhanced NullPointerException messages (Java 14)? How do they help with debugging?
Easy · Java, Java 17+
- View
What is String.formatted() introduced in Java 15? How does it compare to String.format()?
Easy · Java, Java 17+, Strings
- View
What are local records and local classes (Java 16+)? When would you define a record inside a method?
Medium · Java, Java 17+
- View
How does pattern matching with instanceof handle complex conditions and null checks in Java 21?
Medium · Java, Java 17+
- View
Can a Java Record have custom methods, implement interfaces, and be generic? Explain with examples.
Medium · Java, Java 17+
- View
What are common JVM GC tuning flags (-Xmx, -Xms, -XX:+UseG1GC)? How do you choose GC settings for production?
Hard · Java, Memory & JVM, JVM
- View
What are the phases of class loading in JVM (Loading, Linking, Initialization)? When does static initialization occur?
Hard · Java, Memory & JVM, JVM
- View
What is the difference between Java IO and NIO? What are channels, buffers, and selectors in NIO?
Hard · Java, Advanced Java
- View
How do you implement AutoCloseable to work with try-with-resources? Provide a practical example.
Medium · Java, Core Java, Exception Handling
- View
What new String methods were introduced in Java 11 (isBlank, strip, repeat, lines)?
Easy · Java, Java 17+, Strings
- View
How does Optional.stream() (Java 9) integrate Optional with the Stream API?
Medium · Java, Java 8+
- View
What are collection factory methods (List.of, Set.of, Map.of) introduced in Java 9? How do they differ from Arrays.asList?
Easy · Java, Collections, Java 8+
- View
What are private methods in interfaces (Java 9)? How do they help with code reuse in default methods?
Medium · Java, OOP, Interfaces
- View
Explain the static and final keywords in Java. What can they modify and what are common use cases?
Easy · Java, Core Java, Fresher
- View
What are the four access modifiers in Java? Explain their scope with package and inheritance examples.
Easy · Java, Core Java, OOP
- View
How do you read and write files in Java? Explain FileReader, BufferedReader, InputStream, and try-with-resources.
Medium · Java, Core Java, Fresher
- View
How do you write unit tests in Java using JUnit 5 and Mockito? Explain @Test, @Mock, when/then, and verify.
Easy · Java, Core Java, Senior
- View
How does JDBC work in Java? Explain DriverManager, connection pooling (HikariCP), transactions, and isolation levels.
Hard · Java, Advanced Java, Senior
- View
What are deserialization vulnerabilities in Java? How do you prevent insecure deserialization attacks?
Hard · Java, Advanced Java, Senior
- View
How do you maintain code quality at scale in Java teams? Cover coding standards, reviews, static analysis, and technical debt.
Easy · Java, Core Java, Staff
- View
What are best practices for designing Java APIs? Cover backward compatibility, deprecation, and semantic versioning.
Easy · Java, Advanced Java, Staff
- View
How do Maven and Gradle manage Java dependencies? Explain BOMs, dependency conflicts, and version alignment.
Easy · Java, Core Java, Staff
- View
How do you implement structured logging and observability in Java services? Cover MDC, correlation IDs, and metrics.
Easy · Java, Advanced Java, Staff
- View
What is the Java Platform Module System (JPMS)? Explain module-info.java, exports, requires, and migration challenges.
Medium · Java, Advanced Java, Staff
- View
What are OWASP Top 10 risks most relevant to Java applications? How do you apply secure coding practices?
Medium · Java, Advanced Java, Staff
- View
How do you benchmark Java code with JMH? Explain warmup, fork, blackholes, and common pitfalls.
Medium · Java, Advanced Java, Memory & JVM
- View
How do Spring and Hibernate use JDK dynamic proxies and CGLIB? Explain AOP proxy creation at runtime.
Medium · Java, Advanced Java, Staff
- View
How do you analyze JVM heap dumps and thread dumps in production? What tools and patterns do you look for?
Medium · Java, Memory & JVM, Staff
- View
How do you implement idempotency and saga patterns in Java microservices? Provide design and code-level guidance.
Hard · Java, Advanced Java, Staff
- View
How do you design high-throughput Java services? Cover batching, async pipelines, queue sizing, and backpressure.
Hard · Java, Concurrency, Staff
- View
Explain circuit breaker, bulkhead, retry, and rate limiter patterns in Java. When and how do you apply each?
Hard · Java, Advanced Java, Staff
- View
How do you plan and execute a Java version migration (8 → 11 → 17 → 21)? Cover risks, testing, and rollback.
Hard · Java, Java 17+, Staff
- View
How do you decide build vs buy and select Java frameworks/libraries? Explain evaluation criteria and team fit.
Hard · Java, Advanced Java, Staff
- View
How do you design shared Java libraries and platform golden paths for multiple teams? Cover versioning and governance.
Hard · Java, Advanced Java, Staff
- View
Explain the Java ecosystem: JDK vendors (Oracle, Temurin, GraalVM), LTS releases, and support lifecycle.
Easy · Java, Core Java, Architect
- View
Compare monolith, modular monolith, microservices, and event-driven architectures from a Java platform perspective.
Easy · Java, Advanced Java, Architect
- View
How do non-functional requirements (scalability, availability, latency, cost) drive Java architecture decisions?
Easy · Java, Advanced Java, Architect
- View
How do you define service boundaries and API contracts in Java-based systems? Cover DTOs, versioning, and ownership.
Medium · Java, Advanced Java, Architect
- View
What makes a Java application cloud-native? Cover containers, Kubernetes, 12-factor principles, and health probes.
Medium · Java, Advanced Java, Architect
- View
How do you design caching layers and read/write splitting for Java data-intensive applications?
Medium · Java, Advanced Java, Architect
- View
What integration patterns (Kafka, REST, gRPC) work best in Java ecosystems? How do you enforce contract testing?
Medium · Java, Advanced Java, Architect
- View
How do you implement multi-tenancy in Java applications? Compare shared-schema, schema-per-tenant, and DB-per-tenant.
Medium · Java, Advanced Java, Architect
- View
How do you design CI/CD pipelines for Java services? Cover blue-green, canary deployments, and feature flags.
Medium · Java, Advanced Java, Architect
- View
What are GraalVM and native image compilation trade-offs for Java? Cover startup, memory, reflection, and AOT limits.
Hard · Java, Java 17+, Memory & JVM
- View
How do you architect an internal Java platform SDK and shared runtime for dozens of services?
Hard · Java, Advanced Java, Architect
- View
How do you create an org-wide Java LTS adoption roadmap and training plan? Cover governance and phased rollout.
Hard · Java, Java 17+, Architect
- View
How do you model JVM capacity, memory footprint, and cost at scale? Cover autoscaling and FinOps for Java workloads.
Hard · Java, Memory & JVM, Architect
- View
How do you design multi-region resilience and chaos engineering for Java-based distributed systems?
Hard · Java, Advanced Java, Architect
- View
How do you govern Java architecture decisions across teams? Explain ADRs, standards enforcement, and exception processes.
Hard · Java, Advanced Java, Architect
- View
How do you modernize legacy Java monoliths using the Strangler Fig pattern? Cover risk management and incremental migration.
Hard · Java, Advanced Java, Architect