Why is the Java main method static?

前端 未结 30 2203
离开以前
离开以前 2020-11-22 01:41

The method signature of a Java main() method is:

public static void main(String[] args){
    ...
}

Is the

30条回答
  •  星月不相逢
    2020-11-22 01:58

    Recently, similar question has been posted at Programmers.SE

    • Why a static main method in Java and C#, rather than a constructor?

      Looking for a definitive answer from a primary or secondary source for why did (notably) Java and C# decide to have a static method as their entry point – rather than representing an application instance by an instance of an Application class, with the entry point being an appropriate constructor?

    TL;DR part of the accepted answer is,

    In Java, the reason of public static void main(String[] args) is that

    1. Gosling wanted
    2. the code written by someone experienced in C (not in Java)
    3. to be executed by someone used to running PostScript on NeWS

     
    For C#, the reasoning is transitively similar so to speak. Language designers kept the program entry point syntax familiar for programmers coming from Java. As C# architect Anders Hejlsberg puts it,

    ...our approach with C# has simply been to offer an alternative... to Java programmers...

    ...

提交回复
热议问题