Home »
Java programming language
Java System class runFinalization() method with example
System class runFinalization() method: Here, we are going to learn about the runFinalization() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 15, 2019
System class runFinalization() method
- runFinalization() method is available in java.lang package.
- runFinalization() method is used to run the finalize() methods of any object that are already in a queue for disposing of unused objects.
- runFinalization() method is a static method, it is accessible with the class name too.
- runFinalization() method method does not throw any exception.
Syntax:
public static void runFinalization();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is void, it does not return anything.
Example:
// Java program to demonstrate the example of
// runFinalization () method of System Class
public class RunFinalizationMethod {
public static void main(String[] args) {
// print the state of the program
int i = 10;
System.out.println("The value of i is :" + i);
// Here, we are calling the runFinalization() method
// that will call finalize() methods
// for disposing unused objects
Runtime.getRuntime().runFinalization();
System.out.println("Finalization Done.");
}
}
Output
E:\Programs>javac RunFinalizationMethod.java
E:\Programs>java RunFinalizationMethod
The value of i is :10
Finalization Done.