returning from main will cause the application to shut down and the JVM to terminate (unless there's other threads running in which case the application will then terminate as soon as those other threads complete).
Originally posted by Oneal Shaha: And neighter the finally block is executed after the return statement in main()(is it right ???) [ August 30, 2004: Message edited by: Oneal Shaha ]
The correct question would not be what happens after the return statement of the main() method, but rather what happens when control moves out of the main() method. A finally block will always be executed before control moves out of the method, just as for any other method. [ August 30, 2004: Message edited by: Mattias Arthursson ]
could we right the return statement in main method, cuz it is marked as void? would compiler allow us to do this?
posted 16 years ago
Originally posted by adeel ansari: could we right the return statement in main method, cuz it is marked as void? would compiler allow us to do this?
As long as you don't specify a return value it is perfectly legal to include a return statement in a void method, i.e.
Admit nothing. Blame everyone. Be bitter.
posted 16 years ago
Mattias, You are absolutly right
Adeel, Though we mark a method as void we can always write the simple return statement of syntax " return; ". Also in constructores though void return type also is not allowed. But still we can write the simple return statements in constructores
So after the return statement in 'normal' main method, no object is Garbage collected as the garbage collection thread is a daemon thread.
After main() ends and the jvm terminates, the virtual address space it was running in is either liquidated or made available to the next command/program launched in that address space.
Garbage collection is a fine instrument within the jre that frees up the memory occupied by individual objects during program execution. The operating system's process termination logic just eliminates from memory the jvm and everything that the jvm created as if they never existed in memory.
Also, the jvm shares space in real (hardware) memory and swap/paging disk files. This space is marked available to other processes in the system.
SCJP 1.4, SCWCD in process
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad: