AWTPermission example

This is an example of how to create an AWTPermission. AWTPermissions are permissions granted for the AWT Package of Java. In the AWTPermission API there is a list of all the possible AWTPermission target names, and for each one, there is a description of what the permission allows and a discussion of the risks of granting code the permission. In short, to create and check permissions over the AWT you should:

  • Create a new AWTPermission with a specified name, that indicates a specific permission.
  • Use the checkPermission(Permission perm) API method of the AccessController, in order to check whether the access request indicated by the specific permission should be allowed or not,

as shown in the code snippet below.

package com.javacodegeeks.snippets.core;

import java.awt.AWTPermission;

public class Main {

    public static void main(String args[]) {

  try {

AWTPermission appl = new AWTPermission("myRestrictedAwt");


  } catch (AccessControlException ex) {

System.out.println("Access denied");



Access denied

This was an example of how to create and check an AWTPermission in Java.

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button