I found a very interesting thing when trying to use java. Please find the following code:
public class SimpleTest {
static{
System.out.println(Thread.currentThread().getName());
System.exit(0);
}
}
The above program works without any exceptions (well and good, since I exit the static block itself). But as a conclusion, I got the following:
main
Since I did not start the main thread, how is it created. In my understanding, a static block is executed at boot time. Then how does the main stream get into the picture?
Can anyone give a brief description of how compilation, loading and execution are performed in jvm? Also using rt.jar?
Thanks in advance, Brinal
source
share