⚡ Play a quiz
HomeLearnLanguages › Java
Languages · 2 lessons

Java for Interviews

Java interviews for freshers concentrate on two areas more than any other: how memory is managed, and how the collections framework is put together. Both are asked because the answers reveal whether you understand the runtime or only the syntax.

▶ Start with JVM memory model
Lessons
2
Read time
17 m
Practice problems
4
Track
Languages

Lessons in order

What you will be able to do

  • Locals and references live on the per-thread stack; all objects live on the shared heap.
  • ArrayList is the default List; LinkedList rarely wins outside a whiteboard.

Quiz yourself on Java

Reading is not recall. Take a timed quiz on this topic solo, or share a room code and battle friends on it.

⚡ Start the Java quiz

Frequently asked questions

Is Java pass-by-value or pass-by-reference?

Always pass-by-value. For objects, the value copied is the reference, so a method can change the object's state but cannot make the caller's variable refer to a different object.

What is the difference between stack and heap memory in Java?

The stack holds local variables and references per thread and unwinds automatically when a method returns. The heap holds all objects, is shared across threads, and is reclaimed by the garbage collector.

Can a Java program leak memory?

Yes. The collector only removes unreachable objects, so anything still referenced — a static collection that keeps growing, an unregistered listener, an unbounded cache — is retained indefinitely.

What is the difference between ArrayList and LinkedList?

ArrayList is backed by a resizable array: O(1) indexed access, O(n) insertion at the front, and excellent cache behaviour. LinkedList is a doubly linked list: O(1) insertion at the ends, O(n) access by index, and more memory per element.

When should I use a TreeMap instead of a HashMap?

When you need keys in sorted order, or range operations such as floorKey, headMap and subMap. You pay O(log n) per operation instead of O(1) average for that capability.

What causes a ConcurrentModificationException?

Structurally modifying a collection while iterating it with a for-each loop. The iterator detects the modification count changed and fails fast. Use Iterator.remove() or removeIf() instead.

Other topics in Languages