Home »
Java programming language
Java Process destroy() method with example
Process Class destroy() method: Here, we are going to learn about the destroy() method of Process Class with its syntax and example.
Submitted by Preeti Jain, on December 11, 2019
Process Class destroy() method
- destroy() method is available in java.lang package.
- destroy() method is used to terminate the process abnormally.
- destroy() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- destroy() method does not throw an exception at the time of the killing process.
Syntax:
public abstract void destroy();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is void, it returns nothing.
Example:
// Java program to demonstrate the example
// of void destroy() method of Process
import java.io.*;
import java.util.*;
public class Destroy {
public static void main(String[] args) throws Exception {
// Instantiating Process
System.out.println("Process Instantiated");
Process pr = Runtime.getRuntime().exec("C:\\Program Files (x86)\\TextPad 6\\TextPad.exe");
// Destroy a process
pr.destroy();
System.out.println("Process Destroyed");
}
}
Output
Process Instantiated
Process Destroyed