Java does not support destructors, but adds a finalize( ) method which are invoked by the garbage collector prior to reclaiming the memory hold by the object which has the finalize( ) method. you do not know when the objects are going to be finalized. Try Avoiding use of finalize( ) method to release non-memory resources like file handles, sockets, database connections because the platform has only a finite number of these resources, and you do not know when the garbage collection is going to invoked in to release these resources through the finalize( ) method.
C++ requires explicit memory management while Java has automatic garbage collection.
I was reading as above about garbage collector and finalize method as above.
I am not clear on who has finalize method. Do we need to write it?
Also why sockets database connections are non memory resources. Please advise