Java Java Basics Perfecting the Prototype Conditional ints

Still having trouble with the concept of System.exit(0);

Im having trouble with the general concept of what it is used for and why it is a 0 instead of any other digit

1 Answer

michaelcodes
michaelcodes
5,601 Points

Hi again, I will do my best to explain what this is. System.exit is a line of code that is used to terminate the program. It can return either a value of 0 or 1. The 0 means that the code ended as expected. A return value of 1 means that there was some sort of issue.

In practice, you generally are only going to be using System.exit if the user has input that they want to terminate the program. Using System.exit to handle an exception is generally not a good idea. We use the different types of exceptions so that when there is an issue we can catch them, and the program continues to run rather than shutting down.

Hope this helps!