Saturday, 10 June 2017

Java Tutorial: System class in java [exit method] ~ foundjava


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:

CLICK HERE

No comments:

Post a Comment