• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

regarding System.exit(int n)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by invoking this method with an integer argument ranging between 1 to 14 we can shut down the runnibng JVM. What i know is i have to use only arguments between 1 to 14 , and they carry some meaning, and my question is what actually these constants state or represent.


thanks in advance
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you find that information, about that the argument should be in the range 1 to 14?

It doesn't matter what the argument is. System.exit(int n) terminates the JVM, and the value of the argument doesn't matter.

The argument is just the exit code that the JVM passes back to the operating system when the process ends. On for example Unix, you can write a shell script in which you can retrieve the exit code and use it in any way you like.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Jesper says, the argument to System.exit() can be any integer.

If you are running your application inside some outer program (Java or non-Java), then that outer program might impose restrictions on the exit code. Otherwise, there are no restrictions.

A very common exit code is zero. This is often interpreted by the program that ran your Java program as a successful exit, whereas non-zero is often considered to be an error code. However, this is not universally true, and you need to find out what is the case for your environment. It's nothing to do with Java, though; the same would apply to any program.

A last thought: Java programs should not use System.exit() at all, unless they really have to. A Java program will exit just fine when all the non-daemon threads have exited. It is much better to exit this way, as you can be sure that all threads have had a chance to do any necessary clean-up. If you System.exit(), some thread might be in the middle of some operation. Also, code that calls System.exit() is difficult to incorporate into a larger application (e.g. a Web application server), as System.exit() kills the whole process, not just its part of it.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

We can pass any integer number to System.exit() method. Mostly the negative numbers represent the failure of the operation , zero success and positive number some information messages to the OS.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic