In the code below (from Wrox press beginning Java2), what is the purpose of having a return statement in the main method vs not having a return statement. Just seems odd since we dont return anything.
(Marilyn added code tags) [ December 25, 2002: Message edited by: Marilyn de Queiroz ]
"The Rebel army is now the legitimate property of the Army of the Potomac." - Joseph Hooker spoke these pompous words shortly before he was soundly defeated by Robert E. Lee at Chancellorsville
Daniela Ch
Ranch Hand
Joined: Dec 13, 2002
Posts: 96
posted
0
Hi, I know that a return statement in the main will end the program, since it returns control back to the system. In this case, the return is at the end of the main routine...It is a way to stop the threads, since the return will Interrupt their run(). I think... /Daniela [ December 25, 2002: Message edited by: Daniela Ch ]
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
The "main" thread will end when it reaches the ending curly brace whether "return" is there or not. It will also stop the program because the new threads are daemon threads, but you'll notice that some stuff may still print after main() has ended.
I see no function for "return" in this context.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
William Quantrill
Ranch Hand
Joined: Dec 23, 2002
Posts: 36
posted
0
Originally posted by Marilyn de Queiroz: The "main" thread will end when it reaches the ending curly brace whether "return" is there or not. It will also stop the program because the new threads are daemon threads, but you'll notice that some stuff may still print after main() has ended.
I see no function for "return" in this context.
Thats kind what im thinking as well... it doesnt hurt either though
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Here's a nice little example showing that 'return' in main can be useful, i.e. it doesn't necessariliy terminate the program, but it does terminate the current invokation of function main itself:
kind regards
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.