Interview Q&A / Java

INTERVIEW Q&A · 72 QUESTIONS

Java interview questions

Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.

  1. How can a memory leak happen in Java even with garbage collection?

    A leak happens when objects are no longer needed but are still reachable, so GC cannot free them. Common causes are growing static collections, unremoved listeners, unclosed resources and keys in a map that are never removed.

    IntermediateQuick answer1 min read
  2. What are the young and old generations in the Java heap?

    New objects start in the young generation, which is collected often and cheaply because most objects die quickly. Objects that survive several collections are promoted to the old generation, which is collected less often.

    IntermediateQuick answer1 min read
  3. What is Metaspace and how is it different from PermGen?

    Metaspace stores class metadata and, since Java 8, replaced PermGen. PermGen was a fixed-size part of the heap, while Metaspace uses native memory and grows as needed unless MaxMetaspaceSize is set.

    IntermediateQuick answer1 min read