Explain the concept of garbage collection in Java. How can it be triggered manually?
Garbage collection in Java is the process of automatically identifying and removing unused or unreachable objects from memory to free up resources. It helps in preventing memory leaks and optimizing application performance. Java handles garbage collection through the JVM (Java Virtual Machine), which tracks objects no longer referenced by any part of the program. Although it is automatic, developers can suggest garbage collection by calling System.gc(), but it is not guaranteed to execute immediately. Efficient memory management through garbage collection ensures smooth and stable Java applications.

Garbage collection in Java is the process of automatically identifying and removing unused or unreachable objects from memory to free up resources. It helps in preventing memory leaks and optimizing application performance. Java handles garbage collection through the JVM (Java Virtual Machine), which tracks objects no longer referenced by any part of the program. Although it is automatic, developers can suggest garbage collection by calling System.gc(), but it is not guaranteed to execute immediately. Efficient memory management through garbage collection ensures smooth and stable Java applications.