Java Applet runs without a main method?

15,255

Solution 1

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

public void init() {... }

Solution 2

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.

Solution 3

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

Life Cycle of an Applet

Share:
15,255
Nicholas Kong
Author by

Nicholas Kong

Updated on June 12, 2022

Comments

  • Nicholas Kong
    Nicholas Kong about 2 years

    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 applications needs the main method as its entry point?

  • Nicholas Kong
    Nicholas Kong over 12 years
    Oh okay so applets use init and applications uses main. Thanks everyone!