public class GarbageCollectorExample { public static void main(String[] args) { // create instance of a class MyClass obj = new MyClass(); // execute some methods // ... // explicitly invoke the garbage collector System.gc(); } } class MyClass { // constructor public MyClass() { //... } // some methods //... // finalize method protected void finalize() { System.out.println("Garbage Collected"); } }In this example, we create an instance of the `MyClass` class and then execute some methods. Afterward, we explicitly invoke the garbage collector using the `System.gc()` method, which will then call the `finalize()` method in `MyClass` if there are no instances of `MyClass` still being used. Package Library: The `java.io` and `java.lang` packages are part of the Java Standard Library.