Timeline for answer to Why a static main method in Java and C#, rather than a constructor? by Voo
Current License: CC BY-SA 3.0
Post Revisions
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 11, 2012 at 21:12 | comment | added | user40980 | @svick In running an application from the console, one needs an entry point for a console application to start running (on shouldn't start running an arbitrary function). That entry point needs to take a a structure that is most simply defined as array of strings (arguments) presented on the command line. That this method is named main in both C and Java and is a convention followed in many other languages (see en.wikipedia.org/wiki/Main_function ). | |
| Jul 11, 2012 at 20:35 | comment | added | Voo | @svick Except that it's perfectly ok to not return anything from main in C too and such trivialities would hardly confuse anyone anyhow. The point wasn't to recreate c++ and all its mistakes but only to make the programmer more at home. What do you think a C++ programmer will have an easier time reading: Java or objective-c code? What do you think will look more obvious to a C++ programmer a main method or a constructor of some class as entry point? | |
| Jul 11, 2012 at 20:32 | comment | added | svick |
@MichaelT But all those are design decisions that make Java different from C++. So why would be keeping Java the same as C++ be important in the case of main(), when it apparently wasn't important enough in other cases.
|
|
| Jul 11, 2012 at 20:08 | comment | added | user40980 |
@svick int in c to void in java had to with how a return code from an application was generated - in java, its 0 unless System.exit(int) is invoked. The change of parameters has to do with how arrays of strings are passed in each language. Everything in java is in a class - there is no option to have it elsewhere. Changing : to extends is a matter of syntax and are essentially the same. All else is dictated by the language.
|
|
| Jul 11, 2012 at 0:33 | comment | added | Voo | @svick One possibility: Java introduced interfaces and clearly they wanted to separate the two concepts (inheriting interfaces/classes) - with just one "keyword" that won't work. And "quite different"? It's the nearest possible mapping of it and so far I've never seen a c++ programmer have a problem understanding that the static main method is the entry point. Contrary to that having a class called Application or something whose constructor is used, is something that would look strange to most c++ programmers. | |
| Jul 10, 2012 at 22:19 | comment | added | svick |
If looking the same as C++ was so much important for Java, why did they for example change : to extends? And public static void main(String [ ] args) inside a class is quite different than int main(int argc, char **argv) outside of a class.
|
|
| Jul 10, 2012 at 21:41 | history | answered | Voo | CC BY-SA 3.0 |