Site icon DataFlair

Quiz on Java Garbage Collection Algorithm

quiz on java garbage collection algorithm

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Ever wondered how Java keeps track of memory usage and cleans up after unused objects? The answer lies in garbage collection, a fundamental Java mechanism that automatically reclaims memory occupied by objects no longer referenced by your program.

Understanding garbage collection is essential for writing efficient and memory-conscious Java applications. This blog post delves into the world of Java garbage collection, exploring when objects become eligible for collection and the different algorithms used by the Java Virtual Machine (JVM) to manage memory.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    When does the finalize() method invoked in a program ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Sample {

    public void method() {

    System.out.println(“Garbage is collected”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Sample s = new Sample();

    Sample object = new Sample();

    object.method();

    System.gc();

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class GarbageCollection {

    public static void main ( String args [ ] )

    {

    int x = 10;

    x = 5;

    System.out.println(x);

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following methods is used to invoke a garbage collector in Java ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

     class GarbageDemo {

    public void function()

    {

    int a , b , c;

    a = 5;

    b = 10;

    c = null;

    System.out.println(a+b);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    GarbageDemo g = new GarbageDemo();

    g.function();

    }

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class Sample {

    public static void main ( String args [ ] )

    {

    int x = 10;

    x = x + x;

    System.out.println(x);

    System.gc();

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following cannot be garbage collected ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class One {

    public void method()

    {

    System.out.println(“DataFlair”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    void display()

    {

    One o = new One();

    o.method();

    }

    System.gc();

    System.out.println(“Garbage is collected”);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

     class Example {

    public void Display()

    {

    System.out.println(“Finalize method is executed”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Example e = new Example();

    e.Display();

    System.gc();

    }

    void finalize() {

    }

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is not an advantage of Garbage collection ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class GarbageCollection {

    public static void main ( String args [ ] )

    {

    int a ;

    System.out.println(a);

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    class Function {

    public static void main ( String args [ ] )

    {

    System.out.println(“DataFlair”);

    }

    garbageCollector();

    }

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which of the following is used to collect unused objects in Java ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

     class Average {

    public void calculate ( int a , int b , int c )

    {

    int avr = ( a + b + c ) / 3 ;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Average a = new Average();

    a.calculate();

    System.gc();

    }

    void finalize() { 

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    class Main {

    public static void main ( String args [ ] )

    {

    String a;

    String b;

    a = “DataFlair”;

    void print() {

    System.out.println(a);

    }

    System.gc();

    System.out.println(b);

    }

    }

    Correct
    Incorrect

Summary:

This quiz has provided a foundational understanding of Java garbage collection. We explored the concept of object reachability and how it determines when an object becomes garbage. We also examined the different garbage collection algorithms commonly used by the JVM, including mark-and-sweep, copying, and generational collection.

By equipping yourself with this knowledge, you can write more efficient Java code that minimizes memory usage and optimizes application performance.

This quiz also serves as a springboard for further exploration. Consider delving deeper into specific garbage collection algorithms and how to fine-tune them for your application’s unique needs. Additionally, explore tools and techniques for monitoring memory usage and identifying potential memory leaks in your Java programs.

Exit mobile version