Java Applet runs without a main method?

前端 未结 4 2128
野性不改
野性不改 2020-12-11 04:51

I was running a Java class that extends Applet implements Runnable and apparently the program can run, but there is no main method. I thought Java

相关标签:
4条回答
  • 2020-12-11 05:28

    Yes, but applets aren't applications. There is a main method in the applet runner (assuming it's implemented in Java; it need not be) but the applet doesn't work that way; it gets loaded/instantiated from a file and then it proceeds along its lifecycle through initialization, starting, operating, stopping, and finally being destroyed. The code that sends it through these states is hidden from the applet's view; it just knows its in an environment that can run applets.

    0 讨论(0)
  • 2020-12-11 05:36

    Applets differ from stand-alone Java applications in that they do not need to implement a main method.

    Life Cycle of an Applet

    0 讨论(0)
  • 2020-12-11 05:49

    Copied from google results:

    Applets are standalone programs which require a third party tool for its execution that is either it is java enabled web browser or applet runner. So it doesn't have main(). It is possible to run a program without main.

    Possible duplicate of:
    Why do applets not need a main()?

    0 讨论(0)
  • 2020-12-11 05:53

    Java Applets have an init method instead of main. It's:

    public void init() {... }
    
    0 讨论(0)
提交回复
热议问题