A hands-on repo to practise Java for interviews. Every topic has a guide, links, exercises with tests, a reference solution, and "twist" ideas to test your own understanding.
Requirements: JDK 21 and (optionally) Maven. The Maven Wrapper (./mvnw) is included, so only a JDK is strictly needed.
./run.sh --list # list categories
./run.sh # run everything (unsolved exercises fail, that's the point)
./run.sh collections # run one category (lists every test with PASS/FAIL/SKIP, time and purpose)
./run.sh core PointTest # run one test class
./run.sh --solutions # run against reference solutions (sanity check)
./run.sh --learn core # solutions + every test with its purpose (read-only study)
./run.sh --details # per-test list even for a full run
./run.sh --verbose core # also show the raw Maven output
mvn test -Dtest=PointTest#toStringFormat # one test methodIDE: open pom.xml in IntelliJ / VS Code; every test has a run/debug button.
exercises/java/prep/<category>/ <- YOUR CODE: stubs that throw UnsupportedOperationException("TODO")
solutions/java/prep/<category>/ <- reference solutions (same class names; peek after you try)
src/test/java/prep/<category>/ <- tests (same tests verify both)
docs/<category>.md <- guide: concepts, common questions, gotchas, links
- Just want to read? Run
./run.sh --learnand follow docs/solutions-tour.md. - Read
docs/<category>.md. - Open an exercise in
exercises/, read the Javadoc, implement it. ./run.sh <category>until green.- Compare with
solutions/. Every method there has a Javadoc explaining what it does, how it works step by step, an example and its complexity. Read the// TWIST:comments too.
-Dsolutions just swaps the compiled source folder, so the same tests run against the reference code.
- Break it on purpose: follow the
// TWIST:comments insolutions/. Predict what fails, run, compare. (e.g. deletehashCode()fromPoint.) - Predict the output:
src/test/java/prep/core/PuzzlesTest.javaandjvm/JvmDemosTest.java. Cover the assertion, guess, then check. Change an expected value to see the failure message. - Raise the level: tests marked
@Disabled("Level 2 ...")are harder variants. Remove@Disabledafter you extend the code. - Add your own edge cases under
// YOUR EDGE CASES HEREin each test (null, empty, huge, duplicates, negatives). - Explain it back: write time/space complexity and your reasoning in a comment above each solution, then compare with the guide.
- Use git as a safety net:
git switch -c practice/<topic>;git diffshows your twist,git restore .resets it.
Tick them off as you go.
| Done | Category | Guide | Exercises |
|---|---|---|---|
| [ ] | Core Java | docs/core.md | Point, StringPractice, puzzles |
| [ ] | Collections | docs/collections.md | LruCache, CollectionPuzzles |
| [ ] | Modern Java 8-21 | docs/modern.md | StreamPractice, ShapeMath |
| [ ] | Concurrency | docs/concurrency.md | SafeCounter, BoundedBuffer, ParallelSum |
| [ ] | Algorithms | docs/algorithms.md | Searching, Sorting, ArrayTricks |
| [ ] | Data structures | docs/datastructures.md | LinkedListOps, MinStack, TreeOps, GraphOps |
| [ ] | Design patterns | docs/patterns.md | AppConfig, Pizza, EventBus |
| [ ] | Low-level design | docs/design.md | RateLimiter, ParkingLot |
| [ ] | JVM and memory | docs/jvm.md | Team, demos |
| [ ] | Multiple-choice practice | docs/mcq.md | 50 questions (core Java + Spring) with the answer shown and runnable demos for every option |
Suggested order: core -> collections -> algorithms -> data structures -> modern -> concurrency -> patterns -> design -> jvm.
./serve.sh starts a small REST API (Spring Boot + JPA + H2) in spring-demo/; call it with curl, watch the request flow and SQL in the console, change the code and see what breaks. Guide with experiments: docs/spring-server.md.
- Add a stub in
exercises/java/prep/<category>/Foo.javaand the working version insolutions/java/prep/<category>/Foo.java(same package and class name, same public API). - Add
src/test/java/prep/<category>/FooTest.java. - Check both modes:
./run.sh --solutions <category>must be green;./run.sh <category>should fail until solved.
- Links in the guides point at stable, well-known sites (Oracle docs, JEPs, LeetCode, Refactoring Guru, etc.). They were written without network verification, so report any that moved.
- Concurrency tests use timeouts and repeated runs; run them a few times after you think you're done.