learn java
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes arguments of System.exit() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "arguments of System.exit()" Watch "arguments of System.exit()" New topic

arguments of System.exit()

Krishna Acharya
Ranch Hand

Joined: Jun 05, 2007
Posts: 34
Hi there,
Is there anybody to help me in clearifying the no of arguments that system.exit() can hold. For eg. System.exit(0), System.exit(1). In which circumstances we use System.exit(1)? Are there other arguments besides 0 and 1.

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
System.exit only takes one parameter. You can make that parameter any int you want. Typically, you make it 0 to indicate that the program will exit normally. You make it a non-zero value to indicate there was a problem.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14667

If you call your Java program from a shell script (in Unix) or a batch file (in Windows), you can check the return value, which is the value you pass to System.exit(...), in the script or batch file.

Most Unix and Windows programs that return a value like this, return 0 when there's no error and something else when there is some kind of error.

What value you should return depends on what you want to do in the script or batch file under certain conditions.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: arguments of System.exit()