Thursday 4 May 2017

Java Tutorial: System class in java [exit method]


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=uy7ssVHx_U4&list=UUhwKlOVR041tngjerWxVccw

ExitDemo.java
/*
 * public static void exit(int status)
 * 
 * Parameters: 
 * -----------
 * 
 * status - exit status.
 */

public class ExitDemo
{

    public static void main(String[] args)
    {
        try
        {
            int num1 = 30, num2 = 0;
            int output = num1 / num2;
            System.out.println("Result = " + output);
        }
        catch (ArithmeticException e)
        {
            System.out
                    .println("Arithmetic Exception: You can't divide an integer by 0");

            /*
             * Terminates the currently running Java Virtual
             * Machine.The argument serves as a status code;
             * by convention, a nonzero status code
             * indicates abnormal termination.
             * 
             * This method calls the exit method in class
             * Runtime. This method never returns normally.
             * 
             * The call System.exit(n) is effectively
             * equivalent to the call:
             * Runtime.getRuntime().exit(n)
             */
            System.exit(0);
        }

        System.out.println("Welcome to india..");

    }
}
Output
Arithmetic Exception: You can't divide an integer by 0

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/SystemDemo_exit_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/SystemDemo_exit_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f1fa585daa61fc8fa0957d6f04b940eddbcf7ec/BasicJava/SystemDemo_exit_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment