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 following transaction anomalies: dirty reads, non-repeatable reads, phantom reads, lost updates, and write skew. For a banking transfer service that concurrently updates account balances, recommend an isolation strategy and application-level patterns (SELECT FOR UPDATE, optimistic locking with version columns, or serializable isolation) to prevent lost updates while maintaining acceptable throughput. Discuss trade-offs and behavior differences between Postgres and MySQL.
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.
In the context of a Java backend service, describe best practices for exception handling and error propagation. Include guidance on differentiating recoverable vs fatal errors, structuring custom exception hierarchies, mapping exceptions to HTTP responses in Spring Boot, and logging without leaking sensitive information.
Design a high-throughput order processing backend implemented in Java to accept 5,000 orders per second peak with sub-200ms write latency requirements, ensure strong consistency for inventory reservations and payments, and provide APIs for order status queries. Describe overall architecture, how you would partition and scale the relational datastore (sharding strategies, read replicas), where to use synchronous vs asynchronous processing, idempotency handling, and how to ensure and measure availability and throughput. Discuss trade-offs and failure modes.
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.