Code:
import java.awt.Graphics;
/*<applet code="HelloWorld"></applet>*/
public class HelloWorld extends java.applet.Applet {
public void init()
{
resize(150,25);
}
public void paint(Graphics g)
{
g.drawString("Hello world!", 50, 25);
}
}
The code is correct. But when you run from terminal, it will not run till you add the bold lines.
Applets are loaded in a browser. So, either you can create a HTML file named HelloWorld and add the <applet> tag to it.
Or you can add the tag in the Java file itself as above.
And run the program.
Code:
$javac Helloworld.java
$appletviewer Helloworld.java