Objects Recr
Objects Recr
Methods in Java can return objects, allowing for flexible and reusable code
public class Test {
using recursion
o/p
10 + sum(9)
10 + ( 9 + sum(8) )
10 + ( 9 + ( 8 + sum(7) ) )
...
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + sum(0)
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
-------------------------------
The finalize() method in Java is a mechanism provided by the Object class that
allows developers to perform cleanup operations on objects before they are
garbage collected.
Syntax
Protected void finalize()
{
Clean up code
}
---------
Garbage collection in Java is an automatic memory management process that helps
reclaim memory used by objects that are no longer needed. This is crucial for
preventing memory leaks and ensuring efficient use of resources within Java
applications.
What is Garbage Collection?
Definition: Garbage collection (GC) is the process by which the Java Virtual
Machine (JVM) automatically identifies and removes objects that are no longer
referenced by the program, thus freeing up memory space124.
Memory Management: In Java, objects are created in a memory area known as the heap.
When these objects are no longer in use, the garbage collector reclaims their
memory,
preventing potential OutOfMemoryError situations that can occur if the heap
runs out of space.
-------------