JavaHow to Use the halt() Method in Java

How to Use the halt() Method in Java

This Java quick tip teaches developers how to use the halt() method of the Runtime class to forcibly terminate the currently running Java Virtual Machine (JVM). Enter the following code into your code editor or integrated development environment (IDE):


public class RuntimeHalt
	public static void main(String args[])
		RuntimeHalt runtimeHalt = new RuntimeHalt();
	private void proceed()
		System.out.println("Before Runtime.getRuntime().halt()");
		//Invoking halt on the Runtime, terminates the currently running JVM forcibly.
		//The below text is never printed.
		System.out.println("After Runtime.getRuntime().halt()");


When you run this code, you should get a similar output to the following. Note: your output may vary on depending upon your operating system, configuration, and settings.

[[email protected]]# java RuntimeHalt
Before Runtime.getRuntime().halt()

Latest Posts

Related Stories