Timeline for answer to Why is the Java main method static? by yorkw
Current License: CC BY-SA 3.0
Post Revisions
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 20, 2020 at 9:12 | history | edited | Community Bot |
Commonmark migration
|
|
| Jul 16, 2012 at 15:30 | comment | added | Konrad Rudolph |
@Yves It can be. It needn’t, if another design makes sense. I’ve heard some good arguments in the comments here but I still think that a process is effectively very much like a thread (it is), and a thread in Java is usually represented as an instance of Runnable. Representing the whole process in the same way (i.e. having Runnable.Run as the entry point) definitely makes sense in Java. Of course, Runnable itself is arguably a design flaw, caused by the fact that Java doesn’t have anonymous methods (yet). But since it’s there already ...
|
|
| Jul 16, 2012 at 12:19 | comment | added | assylias |
@KonradRudolph Interestingly, Oak (the predecessor of Java) already required the main method to have a similar prototype: public static void main(String arguments[]) - Reference: Oak 0.2 Spec.
|
|
| Jul 15, 2012 at 21:38 | comment | added | Yves Martin |
Generally speaking when a method result computation depends only on its parameters, so that it does not depend on the object instance internal state, it can be static. And it is recommended to set it as static for code maintainability/re-usability. If the method main was not static, it means the class instance state must be known and it is much more complex to define, like which constructor to use first.
|
|
| Jul 15, 2012 at 12:20 | history | made wiki | Post Made Community Wiki by A.H. | ||
| Jul 12, 2012 at 11:14 | history | edited | yorkw | CC BY-SA 3.0 |
deleted 235 characters in body
|
| Jul 12, 2012 at 9:27 | comment | added | yorkw | @KonradRudolph, for questions regarding to language and JVM specification design, perhaps you could try contact original source from Oracle and see if you can get any positive feedback. | |
| Jul 12, 2012 at 6:57 | comment | added | Konrad Rudolph | The problem here is that this is actually a very good answer to the question in its original form, with plenty of references (+1). However, I’d love to learn about the rationale for the design decision of making a static method the entry point, rather than a constructor or instance method. | |
| Jul 12, 2012 at 4:11 | history | edited | yorkw | CC BY-SA 3.0 |
added 122 characters in body
|
| Jul 12, 2012 at 4:05 | history | answered | yorkw | CC BY-SA 3.0 |