Challenge - 5 Problems
Garbage Collection Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 conceptual
intermediate2:00remaining
What is the primary purpose of garbage collection in Java?
Choose the best description of what garbage collection does in Java.
Attempts:
2 left
❓ query result
intermediate2:00remaining
What output does this code produce regarding object finalization?
Consider the following Java code snippet. What will be printed when the program runs?
Java
class Test { protected void finalize() { System.out.println("Finalized"); } public static void main(String[] args) { Test t = new Test(); t = null; System.gc(); System.out.println("End of main"); } }
Attempts:
2 left
📝 syntax
advanced2:00remaining
Identify the syntax error in this garbage collection related code snippet
Which option contains a syntax error preventing compilation?
Java
public class GCExample { public static void main(String[] args) { Object obj = new Object(); obj = null; System.gc(); } }
Attempts:
2 left
❓ optimization
advanced2:00remaining
Which approach helps reduce garbage collection overhead in Java?
Select the best practice to minimize the impact of garbage collection on application performance.
Attempts:
2 left
🔧 debug
expert3:00remaining
Why does this Java program cause a memory leak despite garbage collection?
Examine the code below and select the reason it causes a memory leak.
Java
import java.util.ArrayList; public class LeakExample { static ArrayList<Object> list = new ArrayList<>(); public static void main(String[] args) { while(true) { Object obj = new Object(); list.add(obj); } } }
Attempts:
2 left
