Java System exit() Method
The exit() method of System class terminates the current Java virtual machine running on system. This method takes status code as an argument.
- Note: Status - exit(0) - indicates Successful termination
- Status - exit(-1) - indicates unsuccessful termination with Exception
- Status - exit(1) - indicates Unsuccessful termination
The exit() method of System class terminates the current Java virtual machine running on system. This method takes status code as an argument.
- Note: Status - exit(0) - indicates Successful termination
- Status - exit(-1) - indicates unsuccessful termination with Exception
- Status - exit(1) - indicates Unsuccessful termination
Syntax
Parameter
status - It is the exit status.
Returns
This method does not return any value.
Exception
If security manager exist and his checkexit method doesn't approve exit with specified status then a SecurityException is thorwn.
Example 1
Test it Now
Output:
array[0]=9
array[1]=8
array[2]=7
array[3]=6
terminatingjvm,exiting
array[0]=9 array[1]=8 array[2]=7 array[3]=6 terminatingjvm,exiting
Example 2
Test it Now
Output:
program will terminate when i is 1
your no is 10
your no is 9
your no is 8
your no is 7
your no is 6
your no is 5
your no is 4
your no is 3
your no is 2
your no is 1
Value is 1 now terminating your program
program will terminate when i is 1 your no is 10 your no is 9 your no is 8 your no is 7 your no is 6 your no is 5 your no is 4 your no is 3 your no is 2 your no is 1 Value is 1 now terminating your program
No comments:
Post a Comment