How does garbage collection work in Java?
Garbage collection in Java is the process of automatically reclaiming memory occupied by objects that are no longer reachable or in use by the program. Java has a built-in garbage collector that identifies and removes unreferenced objects, preventing memory leaks and improving overall program efficiency.