Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Parsing Integers

Jan Satsatin
Jan Satsatin
422 Points

Why do we put zero "0" on the "System.exit(0);" statement? Is 0 means yes and 1 is no?

Usage of zero

1 Answer

Steven Parker
Steven Parker
231,271 Points

:point_right: 0 means normal. Anything else is a code indicating what kind of error occurred.


Declaration

public static void exit(int status)

Parameters

status -- This is the exit status. By convention, a nonzero status code indicates abnormal termination.

Jan Satsatin
Jan Satsatin
422 Points

Anything else means we can assign return value to state what error occurred?

Steven Parker : Wouldn't we potentially forcing a normal status on something that might be running abnormally otherwise by placing System.exit(0) within our code? Wouldn't it be better to run it and determine what, if any, errors emerge?

Steven Parker
Steven Parker
231,271 Points

You would only call exit and pass 0 if you intend for the program to end at that point. That means it's a normal ending.

If the program exits because of some error, it will not reach your normal exit call, and the system will give it a non-zero return code automatically.