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.
How would you structure tests for a Java DAO/Repository layer? Explain when to use unit tests, integration tests with an embedded or test database, and contract or migration tests. Name frameworks and tooling you would use (e.g., JUnit, Mockito, Testcontainers) and give examples of what each test type should assert.
Explain dependency injection in Java backend applications and compare constructor injection, setter injection, and field injection in Spring. Describe advantages and disadvantages of each approach, testability implications, and common pitfalls (for example circular dependencies). Provide a short Java (Spring Boot) example showing constructor injection for a Service that depends on a UserRepository.
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.
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.
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.
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.