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