Any2Quiz
Quizzes / Computer Science / Languages / Java

Memory Management Quiz - Languages Java

Free practice quiz: Memory Management (Languages Java). 52 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

This Languages Java practice quiz has 52 multiple-choice questions on Memory Management, and 52 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.

Start quiz: 52 questions, free

Sample questions

  1. In Java, which garbage collector is primarily designed for server-side applications, offering high throughput and low pause times?

    Show answer

    Answer: C. G1 (Garbage-First) Garbage Collector

    The G1 Garbage Collector is optimized for server-side applications, aiming to balance throughput with predictable pause times by dividing the heap into regions and collecting garbage from regions with the most garbage first.

  2. Which of the following is NOT a type of reference in Java that affects garbage collection?

    Show answer

    Answer: D. Abstract reference

    Java has Strong, Soft, Weak, and Phantom references. 'Abstract reference' is not a distinct reference type in this context. Each type influences when an object can be garbage collected.

  3. What does the JVM option `-XX:+UseG1GC` do?

    Show answer

    Answer: C. Enables the G1 (Garbage-First) Garbage Collector

    This JVM flag explicitly instructs the JVM to use the G1 garbage collector.

  4. Which statement best describes the behavior of the 'copying' garbage collection algorithm?

    Show answer

    Answer: B. It divides the heap into two spaces: 'from-space' and 'to-space'. Live objects are copied from 'from-space' to 'to-space' during collection.

    The copying algorithm is efficient for collecting short-lived objects. It minimizes fragmentation by moving all live objects to one space, leaving the other space completely free for the next allocation cycle.

  5. What is the primary benefit of using generational garbage collection?

    Show answer

    Answer: B. It reduces the frequency of full heap scans by leveraging the 'weak generational hypothesis' (most objects die young).

    Generational GC divides the heap into generations (young and old). Since most objects are short-lived and die in the young generation, frequent, quick collections there are efficient. Objects surviving these collections are promoted to the old generation, which is scanned less frequently.

Take the full quiz

More questions in this quiz

Answers and explanations are in the full quiz.

  1. What is the primary role of the 'young generation' in Java's generational garbage collection?
  2. When an object is promoted from the young generation to the old generation (tenured generation) in generational garbage collection, what is the underlying assumption?
  3. Which JVM option is used to explicitly specify the maximum heap size for an application?
  4. What is a 'heap dump' in the context of Java memory management?
  5. Which Java garbage collector is known for its 'stop-the-world' phases, where the application threads are paused for garbage collection?
  6. What is a 'memory leak' in Java?
  7. What is the purpose of the 'Eden space' in the young generation of the heap?
  8. Which JVM option controls the ratio between the old generation and the young generation?
  9. What is the significance of a 'Survivor space' in generational garbage collection?
  10. What is the primary objective of using Weak References in Java?
  11. Which garbage collector aims to provide very low pause times, even at the cost of reduced throughput, by performing most of the garbage collection work concurrently with the application?
  12. What is the 'permgen' (Permanent Generation) in older JVM versions (before Java 8) primarily used for?
  13. In the context of Java Memory Model (JMM), what is 'visibility'?
  14. What is the potential problem with using the Serial Garbage Collector in a multi-threaded application?
  15. What is 'object finalization' in Java, and why is it generally discouraged?
  16. Which garbage collector is known for its region-based approach, dividing the heap into smaller regions and collecting garbage from regions that are likely to be full first?
  17. What is the purpose of the `System.gc()` method in Java?
  18. In Java, what is the difference between the stack and the heap?
  19. What is the primary function of the 'old generation' (tenured generation) in generational garbage collection?
  20. Which of these is a common cause of memory leaks in Java, even with garbage collection?
  21. What is the purpose of a 'soft reference' in Java?
  22. What is the 'Minor GC' (or Young GC) operation in Java's generational garbage collection?
  23. Which Java garbage collector is designed to minimize pause times for applications with large heaps, potentially up to terabytes?
  24. What does the `-XX:SurvivorRatio` JVM option control?
  25. What is the role of the 'Mark-Sweep' algorithm in garbage collection?
  26. Which JVM option is used to set the initial heap size for an application?
  27. What is 'heap fragmentation' in Java memory management?
  28. In Java, what is the purpose of Metaspace (introduced in Java 8)?
  29. What is the primary goal of 'compaction' in garbage collection algorithms like Mark-Compact?
  30. Which Java garbage collector, introduced as a concurrent collector, was known for its effectiveness in reducing pause times but suffered from fragmentation issues?
  31. What is the purpose of the 'tenuring threshold' in generational garbage collection?
  32. Which JVM flag is used to enable verbose garbage collection logging, providing detailed information about GC events?
  33. What is 'reference counting' as a garbage collection mechanism, and why is it less common in Java compared to tracing?
  34. What is the primary difference between a Minor GC and a Major GC (or Full GC)?
  35. Which of the following JVM garbage collectors is designed to provide predictable pause times by dividing the heap into regions and collecting garbage from the fullest regions first?
  36. What is the role of the 'Mark-Sweep-Compact' garbage collection algorithm?
  37. What does the `-XX:MaxGCPauseMillis=<N>` JVM option aim to achieve?
  38. Which of these is generally NOT considered a good practice for managing memory in Java applications?
  39. What is the purpose of the 'phantom reference' in Java?
  40. In the context of G1 GC, what are 'Humongous Objects'?
  41. Which JVM option controls the ratio of Eden space to Survivor spaces?
  42. What is the primary implication of a 'stack overflow error' in Java?
  43. What does the garbage collector do with objects that have survived many Minor GC cycles and are promoted to the old generation?
  44. Which garbage collector is known for its ability to perform incremental compaction, reducing fragmentation over time?
  45. What is the 'happens-before' relationship in the Java Memory Model?
  46. Which JVM option can be used to tune the maximum amount of memory allocated for the 'Metaspace'?
  47. In Java, what is the 'escape analysis' optimization performed by the JVM?

More quizzes

Browse all Java quizzes

More to play

Daily ChallengeA new quiz every day. Keep your streak.HangmanGuess the word, letter by letter.Story QuestLearn through short interactive stories.All quizzesCBSE, ICSE, competitive exams and more.