Garbage Collections Questions and Answers

Practice Mode
Showing 10 of 32 questions
Q21
Which generation in heap memory contains newly created objects?
  • A Old Generation
  • B Young Generation
  • C Permanent Generation
  • D Meta Space
Answer: Option B
Explanation: Young generation stores newly created objects.
Q22
What happens if an object survives multiple garbage collection cycles in young generation?
  • A It gets deleted immediately
  • B It moves to old generation
  • C It becomes permanent
  • D It gets copied to permgen
Answer: Option B
Explanation: Objects moving to old generation after surviving young GC.
Q23
Which garbage collector is designed for applications requiring short pause times?
  • A Serial GC
  • B Parallel GC
  • C CMS GC
  • D G1 GC
Answer: Option C
Explanation: CMS focuses on reducing pause times.
Q24
What is the permgen space in Java?
  • A Permanent object storage
  • B Temporary memory area
  • C Class metadata storage area
  • D Thread stack area
Answer: Option C
Explanation: PermGen stored class metadata and was replaced by Metaspace.
Q25
Which reference type always remains in memory until JVM needs memory?
  • A Strong reference
  • B Soft reference
  • C Weak reference
  • D Phantom reference
Answer: Option B
Explanation: Soft references are cleared when memory is needed.
Q26
What is a memory leak in context of garbage collection?
  • A Too frequent garbage collection
  • B Objects being collected too early
  • C Unintended retention of objects in memory
  • D Automatic memory management
Answer: Option C
Explanation: Memory leaks occur when objects are unintentionally retained.
Q27
Which algorithm uses mark and sweep approach?
  • A Copying collector
  • B Mark and sweep
  • C Generational collector
  • D Incremental collector
Answer: Option B
Explanation: Mark and sweep is a basic garbage collection algorithm.
Q28
What is the main advantage of garbage collection?
  • A Faster execution
  • B Automatic memory management
  • C Smaller memory footprint
  • D Better network performance
Answer: Option B
Explanation: Automatic memory management prevents memory leaks.
Q29
Which exception can occur if JVM runs out of memory?
  • A NullPointerException
  • B OutOfMemoryError
  • C MemoryFullException
  • D StackOverflowError
Answer: Option B
Explanation: OutOfMemoryError indicates insufficient memory.
Q30
What is the young generation in Java heap divided into?
  • A Old and Permanent
  • B Eden and Survivor
  • C Young and Old
  • D Meta and Class
Answer: Option B
Explanation: Young generation has Eden and Survivor spaces.
Questions and Answers for Competitive Exams Various Entrance Test