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.

EasyTechnical
52 practiced

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.

MediumTechnical
50 practiced

You observe sustained high CPU utilization in a Java backend process. Describe step-by-step how you would identify CPU hotspots and expensive code paths in production with minimal impact. Include tools (async-profiler, Java Flight Recorder, jstack sampling), how to interpret flame graphs, and strategies you would use to reduce CPU usage such as algorithmic improvements, caching, or moving work off the hot path.

HardTechnical
54 practiced

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.

HardTechnical
55 practiced

Given the following query that aggregates sales per customer and excludes refunded orders using a subquery:

SELECT c.id, c.name, SUM(o.total_amount) AS spent
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.created_at > now() - interval '90 days'
AND o.id NOT IN (SELECT order_id FROM refunds)
GROUP BY c.id, c.name
ORDER BY spent DESC
LIMIT 100;

The EXPLAIN shows nested loops and high cost. Rewrite or refactor this query for efficiency, recommend indexes and schema changes (for example use LEFT JOIN ... IS NULL or anti-join and indexes on orders(customer_id, created_at)), and explain why your changes improve performance. Also describe how to validate improvements with EXPLAIN ANALYZE and runtime metrics.

MediumTechnical
40 practiced

Design a strategy for applying schema changes to a production relational database used by Java backend services with zero or minimal downtime. Include steps for additive changes, backfilling computed fields, running online backfills, rolling out application code changes, and safe rollback. Mention tools you might use such as Flyway, Liquibase, gh-ost, or pt-online-schema-change.

Unlock Full Question Bank

Get access to all 33 Java Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.