Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the diff between System.Exit(0) or System.Exit(1) or System.Exit(Any Number)

 
UdayK Kumar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you please let me know...

What is the diff between System.Exit(0) or System.Exit(1) or System.Exit(Any Number) in Java?



Uday
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the javadoc for java.lang.System?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a teaser:
The Java API wrote:The argument serves as a status code; by convention, a nonzero status code indicates...
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value means nothing for the Java program itself. The shell calling the Java program can use it to determine what to do next.

A small example of how I usually compile Linux programs from source and install them: These are three separate commands:
- ./configure reads my environment settings, and creates a build script (Makefile) based on them
- make uses the instructions in the generated Makefile to actually compile the code into an executable
- make install then installs the created executable into a specified location

The && work similarly to how they work in Java: if ./configure succeeds the shell will call make. If that too succeeds the shell will call make install. If ./configure fails (e.g. because a required library is missing) then the shell will abort and not call the remainder. Failure is usually indicated by a non-0 return (i.e. 0 is good, everything else is bad).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic