what is the diff between return() and System.exit() in main()? Thanks, Jenny
Joined: Dec 20, 2001
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