You are here: Home / Topics / Program to use getCodeBase() and getDocumentBase() in Java

Program to use getCodeBase() and getDocumentBase() in Java

Filed under: Java on 2023-09-20 06:38:44

// Program to use getCodeBase() and getDocumentBase().

import java.awt.*;
import java.applet.*;
import java.net.*;

/*
<applet code="Applet07" width="300" height="50">
</applet>
*/

public class  Applet07  extends Applet
{
public void paint(Graphics g) 
{
 String msg;
 
 URL url = getCodeBase(); // get code base
 msg = "Code base: " + url.toString();
 g.drawString(msg, 10, 20);

 url = getDocumentBase(); // get document base
 msg = "Document base: " + url.toString();
 g.drawString(msg, 10, 40);
}
}


Output:

D:\Java>appletviewer Applet07.java

About Author:
M
Mr. Dubey     View Profile
Founder and CEO of MCQ Buddy. I just like to help others.