aspose file tools*
The moose likes Java in General and the fly likes n in System.exit(n) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "n in System.exit(n)" Watch "n in System.exit(n)" New topic
Author

n in System.exit(n)

Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
What does 'n' in System.exit(n) signify

The documentation says 'Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. '

I don't exactly get what it's practical use is . What different effect does giving a nonzero status code have? Can we know how after the JVM terminates, which status code was used?

Could anybody please elaborate.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The return code may be used by the caller. If you execute your program on the Windows Prompt, you can check it using errorlevel.


[My Blog]
All roads lead to JavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Check out http://www.coderanch.com/t/507408/java/java/diff-between-System-Exit-or


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Thanks Christophe and Rob.
So you mean to say that the shell script or DOS script that executes the java class will be able to know the status code.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Exactly. Or the Java program that uses java.lang.Process to execute it as well, through the exitValue() and waitFor() methods.
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Thanks. Got it now.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11312
    
  16

or any scripting language. you could use perl to call the program, and get a return code telling you the success or failure.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Thanks Fred, for your input. Incidentally, I am trying to learn Perl and Moose as part of our project requirement. Could you please suggest some good tutorial sites for these.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: n in System.exit(n)