Java 8 Interview Questions for 2–3 Years
Java 8 Interview Questions for 2–3 Years Work through these 12 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.
What is ForkJoinPool common pool starvation and how do you avoid it?
Never block on common pool — no DB/HTTP in parallelStream without custom pool. Use Executors.newFixedThreadPool for blocking batch jobs. CompletableFuture.supplyAsync(task,...
How does spring.config.import work for externalized configuration?
In K8s: spring.config.import=optional:configtree:/etc/secrets/,optional:configtree:/etc/config/ mounts volumes as properties. Vault:...
How do Spring Boot Actuator health probes work with Kubernetes?
Enable probes, configure K8s readinessProbe on /actuator/health/readiness, liveness on /actuator/health/liveness. Custom HealthIndicator for critical deps on readiness group...
SecurityFilterChain vs deprecated WebSecurityConfigurerAdapter?
@Bean SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf.disable()).authorizeHttpRequests(auth ->...
When and why use CQRS (Command Query Responsibility Segregation)?
E-commerce: write Order aggregate to PostgreSQL; project OrderSummaryView to Elasticsearch for search/filter dashboard. Accept projection lag. Not for simple User CRUD. Combine...
What is Metaspace and how do class loading issues cause memory leaks?
Production set MaxMetaspaceSize 256m with monitoring. Investigate Metaspace OOM: heap dump + classloader histogram. Avoid generating unlimited dynamic proxies. OSGi/script...
What is the difference between Comparable and Comparator?
Comparable built into the type — Employee implements compareTo by id. Comparator external — sort by name or salary without changing Employee. Use...
Compare BlockingQueue implementations for producer-consumer workloads.
For order processing, use ArrayBlockingQueue with capacity matching SLA — slow consumer blocks producer instead of OOM. ThreadPoolExecutor with SynchronousQueue +...
How do JPA Specifications (Criteria API) help dynamic queries?
UserSearchSpec.withStatus(status).and(withNameLike(name)) — repository.findAll(spec, pageable). Criteria API verbose — wrap in static factory methods. Alternative: Querydsl or...
HashMap vs ConcurrentHashMap — when and why?
HashMap for single-threaded or external synchronization. ConcurrentHashMap for shared concurrent maps — finer-grained locking than Hashtable. Cannot store null keys/values in...
What is Optional and when should you use it?
Use Optional as return type when absence is expected — findById returns Optional<User>. Chain with map/flatMap/orElseThrow. Do not use for fields, method parameters, or Jackson...
How does Stream API parallel stream work?
parallelStream() splits work across common pool threads. Good for CPU-heavy map on large in-memory collections. Bad for small lists, IO inside stream, or ordered stateful...
Java 8 Interview Questions and Answers · Top 50 Java 8 Interview Questions and Answers (2026 Edition) · Top 40 Java 8 Interview Questions | Must-Prepare before interview. · Java 8 Interview Questions Every Fresher Must Know
All interview question lists · Interview guides · Home · Support the platform