GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Main method doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Main method doubt" Watch "Main method doubt" New topic
Author

Main method doubt

Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
So is the main method the primary thread that springs in to action when we type in java filename in the command prompt.
Is it a thread that does not to be invoked in the conventional manner.
As in Mythread t1=new Mythread();

The thread that does not need to be elaborated on?

Also, I was curious; what convention does one follow to specify the prioity level of a thread in general.
What exactly does 5 mean, "the most important thread" or " the least important one".


From The Demon,
with love.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

When you run Java class, the JVM looks for the "main()" method and creates a thread for it (called main thread). It assign a stack and all the consequent threds ar children of this main thread call stack.

About Thread Priority
Java Thread Priority


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
Please tell me one thing then,
the JVM "makes" a "main thread" out of the main method written by us?
Is it so?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Varun Goenka wrote:
the JVM "makes" a "main thread" out of the main method written by us?

Yes, we need someone to start, and that someone is JVM which creates a non demon main thread for you so that you can execute your code, by executing "main()" method. Now, How JVM do that, is beyond my knowledge, I don't have a code of JVM .exe file
Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
So we can like,use the sleep method, pointlessly, just for fun even though we arent using any thread.
Make things work slowly to "corroborate" the fact that java is slow?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Look, Thread#sleep() and Why Java is Slow is two different questions, they are not related to each other. You can transfer running thread to sleep state by using sleep() method, and the same thing is true about main thread and that' doesn't make Java slow

 
GeeCON Prague 2014
 
subject: Main method doubt