File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

n in System.exit(n)

 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return code may be used by the caller. If you execute your program on the Windows Prompt, you can check it using errorlevel.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out http://www.coderanch.com/t/507408/java/java/diff-between-System-Exit-or
 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Got it now.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or any scripting language. you could use perl to call the program, and get a return code telling you the success or failure.
 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic