Trail: Security Features in Java SE
Lesson: Quick Tour of Controlling Applets
Observe Applet Restrictions
Home Page > Security Features in Java SE > Quick Tour of Controlling Applets

Observe Applet Restrictions

The Java Plug-in uses a Security Manager to keep viruses from accessing your computer through an applet. No unsigned applet is allowed to access a resource unless the Security Manager finds that permission has been explicitly granted to access that system resource. That permission is granted by an entry in a policy file.

The sample WriteFile.java is an applet that tries to create and to write to a file named writetest in the current directory. This applet will not be able to create the file unless it has explicit permission in a policy file.

Type this command in your command window:

appletviewer http://docs.oracle.com/javase/tutorial/security/tour1/examples/WriteFile.html

Type this command on a single line, without spaces in the URL.

You should see a message about a security exception, as shown in the following figure. This is the expected behavior; the system caught the applet trying to access a resource it does not have permission to access.

WriteFile doesn't have permission to write to writetest

Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Quick Tour of Controlling Applets
Next page: Set up a Policy File to Grant the Required Permission