โ† All topics

โ˜• Interview Prep

Java

equals and hashCode, collections internals, strings, exceptions, generics, streams, concurrency, the JVM and modern Java: what Java and Spring teams test.

๐Ÿ“˜ Learn it from scratch

Visual, hands-on lessons for every pattern in this topic. Do the lesson, then come back and the questions click.

100 questions, most asked first

Ranked by how often each question comes up in real interviews. #1 is the most common.

#1The equals() and hashCode() contractCore Java & OOPMediumFree#2How does HashMap work internally?CollectionsMediumFree#3String immutability, the string pool, and == vs equalsCore Java & OOPEasyFree#4Abstract class vs interfaceCore Java & OOPEasyFree#5ArrayList vs LinkedListCollectionsEasyFree#6final vs finally vs finalizeCore Java & OOPEasyFree#7Checked vs unchecked exceptionsExceptionsMediumFree#8JDK vs JRE vs JVMJVM & memoryEasyFree#9Stack vs heap, and how garbage collection worksJVM & memoryMediumFree#10Overloading vs overridingCore Java & OOPEasyFreeUnlock 90 more Java questions ยท all 1,200 questions for $39/year (about 11ยข a day)See full access#11String vs StringBuilder vs StringBufferCore Java & OOPEasy๐Ÿ”’#12What does static mean?Core Java & OOPEasy๐Ÿ”’#13Comparable vs ComparatorCollectionsEasy๐Ÿ”’#14HashMap vs Hashtable vs ConcurrentHashMapConcurrencyMedium๐Ÿ”’#15synchronized vs volatileConcurrencyHard๐Ÿ”’#16Threads, Runnable and ExecutorServiceConcurrencyMedium๐Ÿ”’#17Java Streams: map, filter, reduce, collectStreams & lambdasMedium๐Ÿ”’#18Lambdas and functional interfacesStreams & lambdasMedium๐Ÿ”’#19Using Optional correctlyStreams & lambdasMedium๐Ÿ”’#20How to write an immutable classCore Java & OOPMedium๐Ÿ”’#21Is Java pass-by-value or pass-by-reference?Core Java & OOPEasy๐Ÿ”’#22Generics and type erasureGenericsMedium๐Ÿ”’#23try-with-resources and AutoCloseableExceptionsEasy๐Ÿ”’#24HashSet vs LinkedHashSet vs TreeSetCollectionsEasy๐Ÿ”’#25ConcurrentModificationException and fail-fast iteratorsCollectionsMedium๐Ÿ”’#26public, protected, package-private and privateCore Java & OOPEasy๐Ÿ”’#27What is a deadlock, and how do you prevent it?ConcurrencyHard๐Ÿ”’#28CompletableFuture and async compositionConcurrencyMedium๐Ÿ”’#29What are records, and when should you use them?Modern JavaEasy๐Ÿ”’#30Writing a thread-safe singletonCore Java & OOPMedium๐Ÿ”’#31Autoboxing and the Integer cacheCore Java & OOPMedium๐Ÿ”’#32HashMap vs LinkedHashMap vs TreeMapCollectionsEasy๐Ÿ”’#33Memory leaks in a garbage-collected languageJVM & memoryMedium๐Ÿ”’#34How class loading worksJVM & memoryHard๐Ÿ”’#35AtomicInteger and compare-and-swapConcurrencyMedium๐Ÿ”’#36Thread lifecycle and statesConcurrencyEasy๐Ÿ”’#37wait/notify and the producer-consumer problemConcurrencyHard๐Ÿ”’#38Default methods and the diamond problemCore Java & OOPMedium๐Ÿ”’#39Switch expressions and pattern matchingModern JavaMedium๐Ÿ”’#40Sealed classes and interfacesModern JavaMedium๐Ÿ”’#41Polymorphism and dynamic dispatchCore Java & OOPEasy๐Ÿ”’#42Static nested, inner, local and anonymous classesCore Java & OOPMedium๐Ÿ”’#43Exception handling best practicesExceptionsMedium๐Ÿ”’#44PriorityQueue and heapsCollectionsMedium๐Ÿ”’#45Arrays.asList vs List.of vs unmodifiable listsCollectionsMedium๐Ÿ”’#46Virtual threads (Java 21)ConcurrencyMedium๐Ÿ”’#47ThreadLocal and its pitfallsConcurrencyMedium๐Ÿ”’#48Choosing a garbage collectorJVM & memoryHard๐Ÿ”’#49Bytecode, the interpreter and the JITJVM & memoryMedium๐Ÿ”’#50groupingBy, flatMap and other collectorsStreams & lambdasMedium๐Ÿ”’#51Wildcards, bounded types and PECSGenericsHard๐Ÿ”’#52Serialization and the transient keywordCore Java & OOPMedium๐Ÿ”’#53Reflection and annotationsCore Java & OOPMedium๐Ÿ”’#54Enums are full classesCore Java & OOPEasy๐Ÿ”’#55Shallow vs deep copy, and clone()Core Java & OOPMedium๐Ÿ”’#56When are parallel streams a good idea?Streams & lambdasHard๐Ÿ”’#57Intermediate vs terminal operations (streams are lazy)Streams & lambdasMedium๐Ÿ”’#58ReentrantLock and ReadWriteLock vs synchronizedConcurrencyMedium๐Ÿ”’#59CountDownLatch, CyclicBarrier and SemaphoreConcurrencyMedium๐Ÿ”’#60Unit testing with JUnit 5 and MockitoTestingMedium๐Ÿ”’#61The Java Memory Model and happens-beforeConcurrencyHard๐Ÿ”’#62Integer overflow and numeric typesCore Java & OOPEasy๐Ÿ”’#63Why not use double for money?Core Java & OOPEasy๐Ÿ”’#64Local variable type inference with varModern JavaEasy๐Ÿ”’#65What changed from Java 8 to Java 21?Modern JavaMedium๐Ÿ”’#66Making your own class work in a for-each loopCollectionsMedium๐Ÿ”’#67Strong, soft, weak and phantom referencesJVM & memoryHard๐Ÿ”’#68OutOfMemoryError vs StackOverflowErrorJVM & memoryMedium๐Ÿ”’#69Dependency injection and inversion of controlSpring & ecosystemMedium๐Ÿ”’#70The Builder patternCore Java & OOPEasy๐Ÿ”’#71How does Spring Boot auto-configuration work?Spring & ecosystemMedium๐Ÿ”’#72Spring bean scopes and lifecycleSpring & ecosystemMedium๐Ÿ”’#73@Transactional and its pitfallsSpring & ecosystemHard๐Ÿ”’#74The N+1 query problem in JPA / HibernateSpring & ecosystemHard๐Ÿ”’#75Lazy vs eager loading and LazyInitializationExceptionSpring & ecosystemMedium๐Ÿ”’#76Building a clean REST endpoint in SpringSpring & ecosystemMedium๐Ÿ”’#77Maven vs Gradle and dependency managementSpring & ecosystemEasy๐Ÿ”’#78Mutable objects as HashMap keysCollectionsMedium๐Ÿ”’#79SOLID principles in JavaCore Java & OOPMedium๐Ÿ”’#80Configuration and profiles in Spring BootSpring & ecosystemEasy๐Ÿ”’#81The Fork/Join framework and work stealingConcurrencyHard๐Ÿ”’#82Sizing and shutting down thread poolsConcurrencyMedium๐Ÿ”’#83Check-then-act races and atomic map operationsConcurrencyMedium๐Ÿ”’#84String.split surprisesCore Java & OOPEasy๐Ÿ”’#85Initialization order of static and instance membersCore Java & OOPMedium๐Ÿ”’#86Checked exceptions inside lambdas and streamsStreams & lambdasMedium๐Ÿ”’#87Method referencesStreams & lambdasEasy๐Ÿ”’#88How does Java sort, and is it stable?CollectionsMedium๐Ÿ”’#89Why use ArrayDeque instead of Stack?CollectionsEasy๐Ÿ”’#90Stopping a thread and handling InterruptedExceptionConcurrencyMedium๐Ÿ”’#91Running the JVM in containersJVM & memoryMedium๐Ÿ”’#92Diagnosing high CPU or a hung Java serviceJVM & memoryHard๐Ÿ”’#93The Java Platform Module SystemModern JavaMedium๐Ÿ”’#94equals() with inheritance (getClass vs instanceof)Core Java & OOPHard๐Ÿ”’#95Integration tests with Spring and TestcontainersTestingMedium๐Ÿ”’#96Testing code that depends on timeTestingMedium๐Ÿ”’#97Logging well in Java servicesSpring & ecosystemEasy๐Ÿ”’#98Handling null and NullPointerExceptionCore Java & OOPEasy๐Ÿ”’#99EnumMap and EnumSetCollectionsEasy๐Ÿ”’#100Why naive Java benchmarks lie (JMH)JVM & memoryHard๐Ÿ”’