Java code run by a browser must be an applet, not an
application.
The browser JVM expects the class mentioned in the web page to
extend java.applet.Applet
java.applet.Applet has four methods the browser calls to control the
applet:
public void init() - Called by the browser to inform the
applet that it has been loaded into the system.
initializes the applet
public void start() - Called by the browser to inform the
applet that it should start its execution.
public void stop() - Called by the browser to inform the
applet that it should stop its execution.
public void destroy() - Called by the browser to inform the
applet that it is being reclaimed and that it should destroy
any resources that it has allocated.
These are referred to as the applet life-cycle methods
The applet class does not have a main method; if it has one it is
ignored by the browser.
Instead of starting with the class's main
method, browser JVM's start by calling the referenced applet's
init method.
As bytecodes in the currently executing class reference other Java
classes, those classes are downloaded or accessed, and the JVM executes them.