944,004 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 33013
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 11th, 2005
0

Why is the main method static?

Expand Post »
I've often pondered over this subject. I know the main method has a special signature the JVM looks for, but why is it static?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 11th, 2005
0

Re: Why is the main method static?

Dunno probly cus thats how they want it to work.
Reputation Points: 16
Solved Threads: 9
Master Poster
OurNation is offline Offline
780 posts
since Aug 2004
Mar 12th, 2005
0

Re: Why is the main method static?

i think static has to do w/ how its accessed
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Mar 12th, 2005
0

Re: Why is the main method static?

Quote originally posted by C++ ...
i think static has to do w/ how its accessed
I already knew that.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 12th, 2005
0

Re: Why is the main method static?

>why is it static?
Primarily so that the JVM doesn't have to instantiate your controlling class to get an entry point into the program.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 12th, 2005
0

Re: Why is the main method static?

Quote originally posted by Narue ...
>why is it static?
Primarily so that the JVM doesn't have to instantiate your controlling class to get an entry point into the program.
So that would take longer than having a main method that does the same thing?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 12th, 2005
0

Re: Why is the main method static?

>So that would take longer than having a main method that does the same thing?
If main isn't static then an object of the class must be created first (unless the JVM wants to break its own rules, which isn't unheard of). By requiring main to be static, the environment avoids an unnecessary step. So yes, it would take slightly longer.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 12th, 2005
0

Re: Why is the main method static?

Quote originally posted by Narue ...
>So that would take longer than having a main method that does the same thing?
If main isn't static then an object of the class must be created first (unless the JVM wants to break its own rules, which isn't unheard of). By requiring main to be static, the environment avoids an unnecessary step. So yes, it would take slightly longer.
Thank you Narue, I believe I understand now.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 14th, 2005
0

Re: Why is the main method static?

And be potentially impossible.
Which constructor should the JVM take after all?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 14th, 2005
0

Re: Why is the main method static?

Quote originally posted by jwenting ...
Which constructor should the JVM take after all?
The one it likes most?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: printing my jtable
Next Thread in Java Forum Timeline: Please help me to understand how jtable and model works





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC