| Author |
return() and System.exit()
|
Jian Yi
Ranch Hand
Joined: Feb 01, 2002
Posts: 127
|
|
what is the diff between return() and System.exit() in main()? Thanks, Jenny
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
Try this example: If you run this program as is, the application will terminate immediately. However, if you comment out line 2 and uncomment line 1, you'll see that the application gets caught in an infinite loop. If you take a look at the API Spec for System, you can see the description of the exit method states:
Terminates the currently running Java Virtual Machine...
This means that your application will terminate, no matter what is happening. A return, however, signifies, the successful completion of a method. I hope that helps, Corey
|
SCJP Tipline, etc.
|
 |
Jian Yi
Ranch Hand
Joined: Feb 01, 2002
Posts: 127
|
|
|
Thanks a lot, Corey! Your answers are always so clear!
|
 |
 |
|
|
subject: return() and System.exit()
|
|
|