When the applet class file is not in the same directory, codebase is used.
In Java applets, the codebase
attribute is used to specify the base URL for applet class files. The codebase
attribute allows you to specify the location from which the browser should load the applet’s class files. This attribute is particularly useful when the applet’s class files are not in the same directory as the HTML file that embeds the applet.
Here’s an example of how the codebase
attribute is used in an HTML file to embed a Java applet:
<applet code="MyApplet.class" width="300" height="200" codebase="http://example.com/appletclasses/">
Your browser does not support the <code>applet</code> tag.
</applet>
In this example, the codebase
attribute is set to “http://example.com/appletclasses/“, indicating that the applet’s class files are located at that URL.
So, to answer your question, you use the codebase
attribute in an applet when you want to specify the base URL from which the browser should load the applet’s class files.