Any2Quiz
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.

Play all 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?

    1. Serial Garbage Collector
    2. Parallel Garbage Collector
    3. G1 (Garbage-First) Garbage Collector
    4. CMS (Concurrent Mark Sweep) Garbage Collector
    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?

    1. Strong reference
    2. Weak reference
    3. Soft reference
    4. Abstract reference
    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?

    1. Enables the Serial Garbage Collector
    2. Enables the Parallel Garbage Collector
    3. Enables the G1 (Garbage-First) Garbage Collector
    4. Disables garbage collection
    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?

    1. It identifies all garbage objects and then frees their memory.
    2. It divides the heap into two spaces: 'from-space' and 'to-space'. Live objects are copied from 'from-space' to 'to-space' during collection.
    3. It compacts the memory by moving objects to fill gaps left by garbage.
    4. It is primarily used for the old generation.
    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?

    1. It simplifies memory allocation for all object types.
    2. It reduces the frequency of full heap scans by leveraging the 'weak generational hypothesis' (most objects die young).
    3. It guarantees no 'stop-the-world' pauses.
    4. It eliminates the need for heap dumps.
    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 quizzes

Browse all Java quizzes