A Java mock interview with AI should drill three layers: core Java (the equals and hashCode contract, immutability, exceptions), collections and concurrency, and a coding problem written in Java without an IDE to catch your mistakes. Let an AI interviewer ask the questions and push on mechanisms, write your code in a plain editor with a timer, then paste it into a chatbot for a review. A voice-only AI can't watch you type, so narrate as you code, and check anything the AI claims about Java against the official documentation.
What Java interviews cover
| Area | Typical questions | What the interviewer is checking |
|---|---|---|
| Core language | equals and hashCode, == versus equals, immutability, checked and unchecked exceptions | That you know the contracts behind everyday code |
| Collections | How HashMap works, which list or map to choose, iteration rules | Whether you choose structures for a reason |
| Concurrency | volatile, synchronized, locks, thread pools, concurrent collections, virtual threads | Whether you can spot a race and fix it safely |
| Modern Java | Records, streams, Optional | Whether your Java is current |
| Coding | A problem solved in Java, often in a shared editor | Correct, readable code that compiles in your head |
| Frameworks (backend roles) | Spring questions if the posting lists Spring (Spring Boot interview questions) | Practical experience, not definitions |
More topics are in our Java interview questions guide; concurrency gets its own page on Java multithreading interview questions.
Twelve questions to rehearse, with answer notes
| Question | A strong answer includes |
|---|---|
If you override equals, why must you override hashCode? | Equal objects must return equal hash codes, or hash-based collections such as HashMap and HashSet look in the wrong bucket and can't find them. |
Why can Integer a = 127, b = 127; a == b be true while the same code with 128 is false? | == compares references. Boxing caches values from -128 to 127 by default, so small values share objects. Compare with equals. |
How does HashMap handle collisions? | Keys are placed in buckets by hash; colliding entries share a bucket, very full buckets can be converted to balanced trees, and the table resizes when the load factor is exceeded. |
HashMap or ConcurrentHashMap? | HashMap isn't thread-safe and allows one null key. ConcurrentHashMap is safe for concurrent use without locking the whole map and rejects null keys and values. |
| Checked or unchecked exceptions? | Checked exceptions must be declared or caught at compile time; unchecked ones extend RuntimeException. Give a view on when each fits. |
Why are strings immutable, and why use StringBuilder in loops? | Immutability makes strings safe to share, cache and use as keys; concatenating in a loop creates a new string each time. |
What does volatile guarantee? | Visibility and ordering of reads and writes across threads, not atomicity: count++ on a volatile field can still lose updates. Use AtomicInteger or a lock. |
synchronized or ReentrantLock? | Both give mutual exclusion; the explicit lock adds tryLock, timed waits and an optional fairness policy, at the cost of remembering to unlock in finally. |
| What are virtual threads good for? | Large numbers of tasks that mostly wait on I/O; they're cheap to create. They don't make CPU-bound work faster. |
| What is a record? | A concise, immutable data carrier whose constructor, accessors, equals, hashCode and toString are generated. |
Arrays.asList or List.of? | Arrays.asList is a fixed-size view of the array: set works, add throws. List.of is unmodifiable and rejects nulls. |
Why prefer ArrayDeque to Stack? | Stack is a legacy synchronized class built on Vector; ArrayDeque is the usual choice for stacks and queues. |
Coding problems to pair with them
- Build an LRU cache with
LinkedHashMapin access order, overridingremoveEldestEntry. Follow-up: build it with aHashMapand your own doubly linked list. - Return the k points closest to the origin using a
PriorityQueueof size k. Follow-up: explain the comparator you wrote. - Write a producer and a consumer that share a
BlockingQueue. Follow-up: shut both down cleanly.
A 50-minute Java session script
| Minutes | What happens | What you practice |
|---|---|---|
| 0–12 | Core and collections questions, each with a follow-up | Mechanisms, in two or three sentences each |
| 12–20 | A concurrency scenario: two threads each increment a shared counter 10,000 times; why might the total be less than 20,000? | Naming the race (read, add, write) and fixing it two ways |
| 20–45 | One coding problem in Java in a plain editor, narrated | Code that would compile: imports, generics, exceptions |
| 45–50 | Paste the code in for review; feedback | Hearing what a reviewer flags |
Prompt: a core Java interviewer
Act as a senior Java interviewer for a [backend / Android / general] role. Ask me 6 questions, one at a time, across the equals and hashCode contract, collections internals, exceptions, immutability, concurrency, and modern Java such as records and virtual threads. After each answer, ask one follow-up about the mechanism or a short snippet ('what happens when this runs?'). Don't correct me until the end; then list wrong or incomplete answers with the correct explanation, and tell me which points to confirm in the official Java documentation.
Why it works: follow-ups on mechanisms are where Java interviews separate candidates, and the closing line reminds you to verify.
Prompt: a concurrency bug hunt
Give me a Java concurrency bug as a code snippet of at most 15 lines, such as a shared counter, a check-then-act on a map, or lazy initialization of a shared object. Ask me to find the bug, explain why it happens and fix it two different ways. Then ask what each fix costs. Don't reveal the answer until I've tried.
Why it works: you practice the reasoning interviewers listen for, not just the name of the fix.
Prompt: a Java code review
Review my Java solution to [problem], written without an IDE: [paste]. Check in this order: would it compile (imports, generics, checked exceptions); correctness on two edge cases; complexity; then Java-specific issues: comparators written as 'b - a', autoboxing in hot loops, == on boxed values or strings, and the choice of collection. List the issues before showing a corrected version.
Why it works: without an IDE, compile errors are the first thing an interviewer notices, so the review starts there.
Java traps that cost points in coding rounds
| Trap | Why it bites | Fix |
|---|---|---|
A comparator written as (a, b) -> b - a | Subtraction can overflow for large or negative values and give the wrong order | Comparator.reverseOrder() or Integer.compare(b, a) |
== on Integer or String | Compares references, so results depend on caching | equals |
| Removing from a list inside a for-each loop | Usually throws ConcurrentModificationException | Iterator.remove() or removeIf |
Arrays.asList(...).add(x) | The list is fixed-size, so add throws UnsupportedOperationException | new ArrayList<>(Arrays.asList(...)) |
int mid = (lo + hi) / 2 | lo + hi can overflow for large indices | lo + (hi - lo) / 2 |
| String concatenation in a loop | Builds a new string on every pass | StringBuilder |
Stack for a stack | Legacy and synchronized | ArrayDeque with push and pop |
We ran each of these on a long-term-support JDK before publishing. Mentioning one while you code (“I'll use Integer.compare so this can't overflow”) shows the care interviewers look for.
Rubric for a Java mock
| Criterion | Strong | Weak |
|---|---|---|
| Language mechanisms | Explains contracts and why they exist | Recites definitions |
| Collections | Chooses structures for stated reasons and knows their costs | ArrayList and HashMap for everything |
| Concurrency | Names the race, offers two fixes and their costs | Adds synchronized everywhere |
| Compilable code | Correct imports, generics and exception handling without an IDE | Code that wouldn't compile |
| Correctness and testing | Traces cases by hand, handles nulls and empty input | Happy path only |
| Communication | Narrates decisions as they're made | Silent typing |
A two-week plan
- Days 1–3: core Java and collections rounds with the first prompt; write a one-line note for every answer you had to correct.
- Days 4–5: concurrency bug hunts, two a day.
- Days 6–11: one coding problem a day in Java in a plain editor, reviewed with the third prompt. Lists such as our NeetCode 150 in Java keep the patterns varied.
- Days 12–13: two full 50-minute sessions, one with a person if possible.
- Day 14: review your notes and the traps table, then rest.
For the shape of the coding half, see our coding mock interview guide.
What an AI mock can't do for Java prep
- Compile your code. In a voice mock nothing runs. After the round, compile and test it yourself.
- Keep Java versions straight. Chatbots can mix up which feature arrived when. Confirm version-specific claims in the official documentation, and say which Java version your examples assume.
- Watch you type. It hears your narration, not your keystrokes.
- Sit your assessment. Timed online tests usually forbid outside help. Prepare beforehand.
Where CoPilot Interview fits
CoPilot Interview is an AI interview assistant whose free AI mock interview builds technical and behavioral questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which suits rehearsing explanations of Java mechanisms and concurrency fixes out loud. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. It scores what you say, so keep compiling and reviewing your code separately. Online assessments and live rounds have their own rules, so prepare with it and follow your employer's rules.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.
Frequently asked questions
What is asked in a Java mock interview?
Core Java (equals and hashCode, immutability, exceptions), collections internals, concurrency (volatile, locks, concurrent collections, virtual threads), modern features such as records, and a coding problem written in Java.
Can I practice Java interviews with ChatGPT?
Yes. Ask it for one question at a time with follow-ups on mechanisms, concurrency bugs to find, and a review of your code. Compile and test anything it writes, and confirm version-specific claims in the official documentation.
Should I practice Java coding without an IDE?
If your interview uses a shared editor or whiteboard, yes. Write in a plain editor, keep imports and generics correct yourself, then compile afterwards to see what you missed.
Are virtual threads asked about in interviews?
Increasingly, for backend roles. Explain that they suit large numbers of tasks that mostly wait on I/O, that they're cheap to create, and that they don't speed up CPU-bound work.
Rehearse it out loud before the real one
The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.
Start a mock interview