Recursion in java is a process in which a way(method) calls alone continuously. A way(method) in java that calls alone is called recursive way(method) .
Java Recursion Example 1: Factorial Number
public class Example {
static int factorial(int n){
if (n == 1) return 1; else
return(n * factorial(n-1));
} }
public static void main(String[] args) { System.out.println(“Factorial of 5 is: “+factorial(5));
} }
Output:
Factorial of 5 is: 120 |
Java Junk Set
In java, junk means unfootnoted objects.
Junk Set is process of reclaiming the runtime unused memory automatically. In other words, it is a way(method) to destroy the unused objects.
To do so, we were using free() function in C language and delete() in C++. But, in java it is pull off automatically. So, java gives best memory management.
Advantage of Junk Set
- It makes java memory efficient because junk gatherer removes the unfootnoted objects from heap
- It is automatically done by the junk gatherer so we don’t need to make extra
gc() way(method)
The gc() way(method) is used to produce the junk gatherer to apply cleanup filtering. The gc() is found in System and Runtime classes.
public static void gc(){}
Simple Example of junk set in java public class TestJunk1{
public void finalize(){System.out.println(“progemarcoding.com”);}
public static void main(String args[]){ TestJunk1 s1=new TestJunk1(); TestJunk1 s2=new TestJunk1(); s1=null;
s2=null; System.gc();
progemarcoding.com
progemarcoding.com |
} }