Pin It

How to terminate a program using System and Runtime class in Java ?.

Program to demonstrate how to terminate a program using System and Runtime class in Java

package com.hubberspot.example;

public class JavaTerminate {

 public static void main(String[] args) {

  int i = 0;

  if (i > 0) {
   // 1. In order to terminate a Java Application
   // we can use System.exit(int) to exit a Java 
   // Application.
   System.exit(i);
  }
  else {
   // 2. In order to terminate a Java Application
   // another way we can use is creating a Runtime Object
   // and calling exit(int) of Runtime to terminate the Java 
   // Application.
   Runtime runtime = Runtime.getRuntime();
   runtime.exit(i);
  }

 }

}



Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot