I am new to applets and came across something unusual. In one of the programs I went through, applet html tag
is mentioned as a comment in the Applet Java file (.java)
but the comment seems to be getting executed. How is this possible?
Code:
import java.awt.*;
import java.applet.*;
/*<applet code="MyApplet" width=100 height=50></applet> */
//why we give comment here and how it is executed ??
class MyApplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet",100,100);
}
}
Comment:
/*<applet code="MyApplet" width=100 height=50></applet> */
How is the above comment getting executed? Aren't comments meant to be skipped?
Why is this method not mentioned on Oracle or any other websites? Even Oracle asks to create seperate HTML file. So does this method use some 3rd party library to execute the comment?
I am also getting an error when I don't make the class public and when I keep the file and class name different.
Can someone please explain this method? I googled a lot but an explanation for this method of including the tags in a comment is nowhere to be found. There is a post on SO but the answer is not up to the point. Please Help.
How could someone accidentally figure out that this is possible? Is this any particular feature of the Applet Class?