Java Programming Questions
The Java language and platform: type system, collections framework, generics, exceptions, the memory and JVM model, and idiomatic object-oriented Java. Covers writing correct Java and reasoning about its runtime and language semantics. A staple server-side and test-automation language surface.
Design a custom JDBC connection pool for Java applications. Describe the key components and algorithms: connection acquisition and release, max pool size, wait time and backpressure behavior, validation of connections, eviction of stale or broken connections, leak detection, and metrics to expose. Explain how you'd implement leak detection and how to avoid thundering herd when the pool is exhausted.
After a production deploy, the 99th percentile latency for a Java service increased dramatically. Traces show a single DB query changed from 10ms to 1.5s and is performing a sequential scan. Outline an incident response plan: immediate mitigations to reduce user impact, steps to identify the root cause (code changes, query plan, statistic changes), how to perform safe rollback or hotfix, and how to write a postmortem with actionable items to prevent recurrence.
Implement or outline a thread-safe LRU cache in Java that supports O(1) get and put operations, an optional TTL per entry, and an eviction callback. Provide the public API and describe an implementation using ConcurrentHashMap and a concurrency-friendly eviction structure, or explain how to use existing libraries (e.g., Caffeine) and why they are preferable. Discuss correctness under concurrency and tests you'd write to validate behavior.
Explain why using SELECT * can be problematic in high-traffic production services that interact with a relational database. Discuss impacts on network I/O, preventing index-only scans, coupling to schema changes, and how to diagnose and fix queries that are I/O-bound because they select wide rows.
You observe frequent long GC pauses (hundreds of milliseconds) on a Java 11 service when load increases. Outline diagnostic steps to determine whether GC is the root cause and propose tuning and configuration changes to reduce pauses: heap sizing, G1 tuning parameters, garbage collector choices (G1 vs ZGC vs Shenandoah), GC logging and analysis, and how to validate improvements in staging and production.
Unlock Full Question Bank
Get access to all 33 Java Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.