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.
Explain the difference between synchronized, volatile, and java.util.concurrent.atomic.AtomicInteger in Java. For each, describe the guarantees provided about memory visibility and atomicity, and give an example scenario where it is the appropriate choice.
Explain the difference between a primary key, a unique constraint/index, and a foreign key in a relational database. For each, give an example use case and discuss performance implications such as index usage for lookups and insert/update overhead. Also mention how each concept maps to JPA/Hibernate annotations.
You need to add a new NOT NULL column with a computed default to a table containing 2 billion rows without blocking writes or causing long locks. Design a zero-downtime migration plan detailing schema rollout steps, backfill strategy (chunked updates, background workers), how to avoid table rewrites or large transactions, how to change the application to be compatible across versions, and how to validate correctness.
A search API performs a JOIN between products and inventory tables and the call now takes roughly 2 seconds, blocking user requests. Describe a structured approach to diagnose why the join is slow: which metrics to look at (I/O, locks, CPU), how to get and interpret query plans, what to check in the database (indexes, stats, vacuuming), and concrete fixes such as indexing, denormalization, materialized views, or moving to a read-optimized store.
Design a caching strategy to reduce database load for user profile reads where updates must be visible immediately to subsequent reads (strong consistency). The service is Java/Spring Boot and uses a relational DB. Propose an architecture including cache type (distributed vs local), invalidation/eviction strategy, and how to implement atomic invalidation with database updates, considering multi-instance coherence.
Unlock Full Question Bank
Get access to all 35 Java Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.