150+ Essential Java Interview Questions: Collections, JVM, Concurrency, Spring & More

This article compiles over 150 Java interview questions covering collections, JVM tuning, concurrency, Spring framework, design patterns, Spring Boot, Netty, and Redis, providing a comprehensive study guide to help candidates prepare for upcoming interview seasons.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
150+ Essential Java Interview Questions: Collections, JVM, Concurrency, Spring & More

Java Collections (22 topics)

Differences between ArrayList and Vector (synchronization, growth strategy).

Performance characteristics of ArrayList, Vector, and LinkedList (random access vs. insertion/removal).

Fail‑fast vs. fail‑safe iterators and their behavior during concurrent modification.

Internal data structure of HashMap (array of buckets, linked list/tree).

How HashMap works (hashing, bucket index calculation, collision handling).

Conditions that trigger HashMap resizing (load factor, threshold).

Characteristics of List, Map, and Set when storing elements (ordering, uniqueness, key‑value mapping).

Duplicate detection in a Set (use of equals() and hashCode(), not ==).

Contract between equals() and hashCode() (equal objects must have identical hash codes).

Heap vs. stack memory allocation in Java.

Core interfaces of the Java Collections Framework ( Collection, List, Set, Map, Queue).

Differences between HashSet and TreeSet (hashing vs. sorted tree).

Underlying implementation of HashSet (backed by a HashMap).

Implementation principle of LinkedHashMap (hash table + doubly‑linked list for insertion order).

Why most collection classes do not implement Cloneable or Serializable directly.

Definition and purpose of an Iterator.

Differences between Iterator and ListIterator (bidirectional traversal, element modification).

Array vs. ArrayList usage scenarios (fixed size vs. dynamic resizing).

Best practices for using the Java Collections Framework (prefer interfaces, choose appropriate implementation, avoid unnecessary synchronization).

Purpose and differences of Comparable vs. Comparator (natural ordering vs. external ordering).

Difference between Collection (interface) and Collections (utility class).

JVM & Tuning (21 topics)

Java class loading process and the underlying mechanism for loading .class files.

Memory allocation areas in the JVM (heap, stack, metaspace, etc.).

Purpose of garbage collection (GC) and its necessity.

Overview of Java GC mechanisms (generational collection, stop‑the‑world pauses).

How to determine object liveness and GC eligibility.

Advantages and principles of different GC algorithms (e.g., Serial, Parallel, CMS, G1).

Whether GC can reclaim memory immediately and ways to request GC ( System.gc(), Runtime.gc()).

Concept of memory leaks in Java (unreleased references).

Deep copy vs. shallow copy semantics.

When finalize() is invoked and its intended use.

Effect of setting a reference to null on memory reclamation.

Distributed Garbage Collection (DGC) and its operation.

Differences between Serial and Throughput collectors.

Conditions under which an object becomes eligible for GC.

Explanation of Minor GC and Major GC, including allocation and reclamation strategies.

Garbage collection behavior for the permanent generation (now metaspace).

Various GC algorithms available in the JDK.

Types of class loaders (Bootstrap, Extension, Application, custom) and the parent‑delegation model.

Concurrent Programming (28 topics)

Principle of the synchronized keyword and its reentrancy.

What a lock represents in Java and how it is associated with an object.

JVM optimizations for native locks (biased locking, lightweight locking).

Why synchronized is considered a non‑fair lock.

Lock elimination and lock coarsening techniques performed by the JIT.

Difference between pessimistic ( synchronized) and optimistic locking (CAS).

When optimistic locking is appropriate and its limitations.

Implementation differences between ReentrantLock and synchronized.

Overview of the AbstractQueuedSynchronizer (AQS) framework.

Detailed comparison of synchronized vs. ReentrantLock (features, performance, interruptibility).

How ReentrantLock achieves reentrancy.

Common utilities in java.util.concurrent (e.g., ConcurrentHashMap, Atomic* classes).

ReadWriteLock and StampedLock concepts and usage.

Synchronization mechanisms and synchronizers (e.g., CyclicBarrier, CountDownLatch, Semaphore, Exchanger).

Implementation of Java thread pools, core construction parameters ( corePoolSize, maximumPoolSize, keepAliveTime, workQueue).

Thread creation strategy inside a pool (eager vs. lazy).

Default thread‑pool implementations ( ThreadPoolExecutor, ScheduledThreadPoolExecutor, ForkJoinPool) and their differences.

Submitting tasks to a thread pool ( execute(), submit(), invokeAll()).

Java Memory Model (JMM) and visibility of variables across threads.

Characteristics of volatile (visibility, ordering) and its limitations (no atomicity).

Comparison of volatile with synchronized.

How ThreadLocal provides thread‑confined storage and precautions when using it.

Spring Framework (25 topics)

Core modules of Spring (Core, Beans, Context, AOP, Data, MVC, etc.).

Benefits of using Spring (dependency injection, modularity, testability).

Inversion of Control (IoC) and Dependency Injection (DI) concepts.

Difference between BeanFactory and ApplicationContext.

Configuration methods: XML, Java‑based @Configuration, and annotation‑driven configuration.

Spring bean lifecycle phases (instantiation, property population, initialization, destruction).

Bean scopes (singleton, prototype, request, session, global session) and their characteristics.

Inner beans and their usage.

Thread‑safety of singleton beans (stateless vs. stateful considerations).

Injecting collections ( List, Set, Map) and Properties into beans.

Bean autowiring mechanisms and modes (byName, byType, constructor, @Autowired).

Enabling annotation‑based autowiring ( @ComponentScan, @Autowired).

Examples of @Required, @Autowired, and @Qualifier annotations.

Constructor injection vs. setter injection.

Spring event types and publishing/subscribing mechanisms.

Difference between FileSystemResource and ClassPathResource.

Design patterns employed by Spring (Factory, Proxy, Template Method, Observer, etc.).

Design Patterns (10 topics)

Common JDK design patterns (Singleton, Factory, Observer, Decorator, Strategy, Template Method, etc.).

Definition of a design pattern and typical usage.

Thread‑safe Singleton implementation in Java (e.g., enum singleton or double‑checked locking).

Observer pattern explanation and typical Java usage (e.g., java.util.Observer).

Benefits and typical use‑cases of the Factory pattern.

Decorator pattern example and whether it operates at object or class level.

Reason static methods cannot access non‑static members (lack of instance context).

Design considerations for an ATM system (modular components, transaction handling).

Guidelines for choosing method overloading vs. overriding.

When to prefer an abstract class over an interface (shared code, backward compatibility).

Spring Boot (22 topics)

Definition and advantages of Spring Boot (auto‑configuration, starter dependencies, embedded servers).

JavaConfig concept in Spring Boot.

Techniques for reloading changes without restarting (DevTools, hot swapping).

Monitors in Spring Boot (actuator health, metrics).

Disabling security on Actuator endpoints.

Running Spring Boot on a custom port ( server.port property).

YAML configuration format and its use in Spring Boot.

Implementing security (Spring Security basics, authentication, authorization).

Integrating ActiveMQ with Spring Boot (starter, JMS template).

Pagination and sorting support (Spring Data Pageable, Sort).

Swagger integration for API documentation.

Spring Profiles for environment‑specific configuration.

Spring Batch overview (job, step, reader, processor, writer).

FreeMarker template engine usage.

Exception handling strategies (global @ControllerAdvice, @ExceptionHandler).

Common Maven starter dependencies (web, data‑jpa, actuator, security, etc.).

CSRF attack concept and mitigation.

WebSocket support in Spring Boot.

Aspect‑Oriented Programming (AOP) basics.

Apache Kafka integration basics.

Monitoring multiple Spring Boot microservices (Spring Cloud Sleuth, Zipkin, Prometheus/Grafana).

Netty (10 topics)

Differences among BIO, NIO, and AIO I/O models.

Components of Java NIO (Channels, Buffers, Selectors).

Key features of Netty (asynchronous, event‑driven, high performance).

Netty threading model (EventLoopGroup, boss/worker threads).

Causes of TCP packet sticking and splitting and typical solutions (delimiter, length‑field framing).

Supported serialization protocols (Java serialization, Protobuf, JSON, Kryo, etc.) and selection criteria.

Zero‑copy techniques used by Netty (FileRegion, CompositeByteBuf).

Performance advantages of Netty (low latency, high throughput, resource efficiency).

Reference to Netty source code for NioEventLoopGroup (location in Netty repository).

Redis (16 topics)

Overview of Redis and its core characteristics (in‑memory, key‑value store).

Supported data types (strings, hashes, lists, sets, sorted sets, streams).

Reason Redis runs as a single‑process, single‑threaded server.

Virtual memory handling in Redis.

Redis locking mechanisms (SETNX, RedLock).

Read‑write separation model (master‑slave replication).

Data sharding strategies (hash slot, cluster mode).

Eviction policies (volatile‑LRU, allkeys‑LRU, LFU, etc.).

Benefits of using Redis over alternatives (speed, rich data structures).

Comparison with Memcached (persistence, data types, clustering).

Common performance issues (memory fragmentation, large keys, blocking commands) and mitigation techniques.

Strategies to keep hot data in Redis when underlying MySQL holds a much larger dataset (caching policies, expiration, LRU).

Ideal use cases for Redis (caching, session store, leaderboards, pub/sub, rate limiting).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMBackend Developmentconcurrencyspringinterview-questions
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.