All specialtiesTechnology · Job interview

Java developer

Knowing Java is half the job. The other half is explaining it clearly in English, under pressure. These five questions come up again and again.

Words → phrases → sentences → speaking

Try SpeakRole ↗
Job interviewJava developer
V

How does a HashMap work, and when would you not use one?

0:18
Interviewer question

Java developer

Interviewers for Java roles usually start with the core language and collections, then move to concurrency, Spring and design. A clear spoken explanation of the basics often matters more than an exotic detail, because it shows that you understand why the code works.

Practise explaining each answer in three steps: a short definition, how it works, and when it matters in a real project. That order keeps you from rambling and gives the interviewer an easy place to ask a follow-up question.

  • ✓Words → phrases → sentences → speaking
  • ✓Answer meaning
  • ✓Language

Common questions and sample answers

How does a HashMap work, and when would you not use one?

What the interviewer wants to hear. The mechanism (hash, bucket, collisions, resizing), the complexity, and the limits: no ordering and no thread safety.

Sample answer to practise aloud

A HashMap stores entries in an array of buckets. It calls hashCode on the key, turns that into an index and puts the entry in that bucket. If two keys land in the same bucket, they are kept in a list, and in modern Java a long list becomes a tree. When the map is more than 75 percent full, it doubles the array and redistributes the entries. Get and put are O(1) on average. I would not use it when I need ordering, so I choose LinkedHashMap or TreeMap, or when several threads write at the same time, where ConcurrentHashMap is the right choice.

What is the contract between equals and hashCode?

What the interviewer wants to hear. The rule itself, and the bug that appears when it is broken.

Sample answer to practise aloud

If two objects are equal according to equals, they must return the same hashCode. The opposite is not required: different objects may share a hash code. If I override equals but forget hashCode, hash-based collections stop working correctly. For example, I put an object in a HashSet, then create an equal object and call contains, and the result is false, because the second object looks in a different bucket. I also try to base both methods on immutable fields, so the hash code does not change while the object is inside a collection.

What is the difference between ArrayList and LinkedList?

What the interviewer wants to hear. Complexity, memory use and a practical recommendation, not only the textbook table.

Sample answer to practise aloud

ArrayList is backed by an array, so reading by index is O(1), and adding to the end is O(1) amortised. Inserting in the middle is O(n), because elements must shift. LinkedList stores nodes with links, so inserting or removing at a known node is fast, but reading by index is O(n), and every element uses more memory. In practice I almost always use ArrayList, because arrays work well with the processor cache. If I need a queue or a stack, I choose ArrayDeque instead of LinkedList.

Why is String immutable in Java?

What the interviewer wants to hear. Several benefits, and at least one practical consequence such as StringBuilder.

Sample answer to practise aloud

Once a String is created, its content cannot change. This gives us a few benefits. Strings are thread-safe without any locks. They can be used safely as HashMap keys, and the hash code can be cached. The JVM can also reuse equal strings from the string pool to save memory, and values like file paths cannot be changed after they have been checked. The price is that concatenation in a loop creates many objects, so for that case I use StringBuilder.

What is the difference between checked and unchecked exceptions?

What the interviewer wants to hear. The compiler rules, when to use each kind, and what your team prefers.

Sample answer to practise aloud

Checked exceptions extend Exception but not RuntimeException. The compiler forces you to catch them or declare them. Unchecked exceptions extend RuntimeException, and the compiler does not check them. Checked exceptions are meant for situations the caller can reasonably recover from, like a missing file. Unchecked ones usually mean a programming error, like a null pointer. In modern projects, especially with Spring, many teams prefer unchecked exceptions, because checked ones make method signatures noisy. What matters is to be consistent and never to swallow an exception silently.

How to say the key terms

Java
JAH-vuh
hashCode
HASH-code
immutable
ih-MYOO-tuh-bul
queue
kyoo
amortised
AM-or-tized
iterator
IT-uh-ray-ter

Useful phrases for answering

  • Let me explain how it works step by step.
  • The main idea is…
  • In practice, I usually…
  • The trade-off here is…
  • That depends on the use case.
  • I haven't used that in production, but as far as I know…
  • Under the hood, it…

Common mistakes to avoid

  • Saying "it depends" and stopping. Say what it depends on, and give one example for each side.
  • Reciting a definition with no example. Add one sentence from real work: "In our service we used…"
  • Mispronouncing basic terms such as queue, cache or thread. Interviewers forgive an accent, but an unclear key word makes the whole answer hard to follow.
  • Pretending to know. "I have not worked with that, but I would start by…" is a stronger answer than a guess.

Frequently asked questions

Do I need to know Java 21 features for an interview?

For most roles, at a basic level, yes. Records, sealed classes, pattern matching and virtual threads are common follow-up topics. Be ready to say which version your last project used and what you liked about newer ones.

Will I write code or only speak?

Often both. Say what you are doing while you write: "First I will handle the empty input, then…" Speaking while coding is a skill that needs practice, because most developers code in silence.

How do I prepare if my English is weaker than my Java?

Choose 15 to 20 core topics and say each of them aloud in English several times. Record yourself, check the key terms, and focus on structure rather than perfect grammar.

Reading an answer is not the same as saying it. Practise each question out loud, then compare the meaning and the language of your own answer.

Try SpeakRole ↗

Other topics in this area