Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

18
  • 74
    +1: Very fascinating (especially the part about writing a custom java.exe) Commented May 1, 2011 at 9:15
  • 11
    Interesting, I do disagree with the "This is just convention." Part of the answer. The OP's primary question was the reason for static in the declaration. I don't think static in the main() declaration is just for the sake of convention. The fact that it's `main()' and not something else is feasible however. Commented Jul 15, 2012 at 1:15
  • 2
    @David So it did. I actually would have preferred an answer from one of the people originally involved – but that was a very far shot. Most of the other answers are unfortunately an exercise in ad-hoc reasoning. This one gives quite interesting details, besides having the humility not to invent wrong technical details to reason away a (probably) non-technical cause. Commented Jul 17, 2012 at 19:45
  • 2
    @Jared - They could have required a public no-arg constructor and made main non-static and still fit within the bounds of the language. Without hearing from the designers, we'll just have to agree to disagree. :) Commented Jul 17, 2012 at 20:58
  • 5
    @BenVoigt You call LoadLibrary() to get the jvm dll. Then you call getprocaddress("JNI_CreateJavaVM"), then you invoke the JNI_CreateJavaVM function (docs.oracle.com/javase/1.4.2/docs/guide/jni/spec/… ). Once the VM is loaded you use standard JNI calls to find the correct class, load the static main method and invoke it. There's not a lot of room for misinterpretation there. JNI is absolutely how you load the VM. You may be used to writing only client side JNI using the native keyword, javah -jni, etc... but that's only half of JNI. Commented Dec 5, 2012 at 4:04