Reputation: 827
which is the thread that will begin as soon as the execution of a java program begins? This was asked in an interview for me. so can anyone suggest the answer here
Upvotes: 3
Views: 85
Reputation: 1436
The 'main()' method in Java is referred to the thread that is running, whenever a Java program runs. It calls the main thread because it is the first thread that starts running when a program begins. Other threads can be spawned from this main thread. The main thread must be the last thread in the program to end. When the main thread stops, the program stops running.
Main thread is created automatically, but it can be controlled by the program by using a Thread object. The Thread object will hold the reference of the main thread with the help of currentThread() method of the Thread class.
for more details check this link
Upvotes: 0
Reputation: 13427
The thread which is created when you start is called the main thread
. It is the one which invokes the main
method.
Edit: apparently someone beat me to the answer.
Upvotes: 1
Reputation: 32488
From Thread
API document
When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class).
And this thread will be called as main thread.
Upvotes: 4