Reputation: 1469
I know in we can terminate JVM with System.exit(), but in java doc ,they written as >>
"This method never returns normally.". What does it means?
Upvotes: 0
Views: 156
Reputation: 533520
The documented purpose of this method is to stop the application.
Notes:
I assume the question is;
When does System.exit(n) return?
When you have an application server, running multiple applications, you don't want one to bring down the whole JVM. In this situation you typically have a SecurityManager which prevents a number of operations esp System.exit(). In this situation, a SecurityException can be thrown, or the JVM shuts down the specific application being run.
Upvotes: 1
Reputation: 1381
It means the program doesn't cleanly return from where it us executing. An exception thrown is also a case where the program doesn't 'cleanly' return.. As in executing through the end. Exit call abruptly terminates the execution flow.
Upvotes: 0
Reputation: 262504
It means that the next line of code after System.exit won't be executed (because the JVM was shut down before getting there).
Upvotes: 0
Reputation: 2208
This means program stops its execution from that line of code and it will not execute return statement and will even not call finally block
Upvotes: 2
Reputation: 8068
After the call System.exit()
your application will terminate immediately not executing and code following the exit()
statement. Look at this example:
public static void main(String[] args) {
System.out.println("about to exit");
System.exit(1);
System.out.println("returned normally");
}
OUTPUT:
about to exit
The second statement System.out.println("returned normally")
got never called.
Upvotes: 0