Skip to content
Related Articles

Related Articles

Improve Article
java.lang.management.ManagementPermission Class in Java
  • Last Updated : 28 Mar, 2021

java.lang.ManagementPermission Class contains abstract methods to determine access to a system resource. Every object has some name. Most permission object also has some “actions” associated with it that tells which activities are permitted by this permission object.

Class declaration :

public final class ManagementPermission
extends BasicPermission

Constructor:

Permission(String name)

public Permission(String name): Constructs a new Permission object with this name.

Method:



MethodDescription 
checkGuard(Object object)It is used to determine if this Permission object can be guarded (protect access to another object) or not.
equals(Object obj)It checks whether two Permission objects are equal or not.
hashCode()It returns the hash code value for this Permission object.
getName()It returns the name of this Permission.
implies(Permission permission)It checks whether this ManagementPermssion object implies this permission or not.
newPermissionCollection()It returns a new PermissionCollection object.
toString()It returns a string representation of the specified Permission object.

1.public void checkGuard(Object object): It is used to determine if this Permission object can be guarded (protect access to another object) or not.

Parameters:
object - the object to guard.
Throws:
SecurityException - if the access is denied by checkPermission method.

2.public abstract boolean implies(Permission permission): It checks whether this ManagementPermssion object implies this permission or not.

Parameters:
permission - the permission to check against.
Returns:
true if this permission is implied by this object, false otherwise.

3.public abstract boolean equals(Object obj): It checks whether two Permission objects are equal or not.

Parameters:
obj - the object to be compared
Returns:
true if both Permission objects are equal, false otherwise.

4.public abstract int hashCode(): It returns the hash code value for this Permission object.

Returns:
a hash code value for this object.

5.public final String getName(): It returns the name of this Permission.

Returns:
the name of this Permission.

6.public abstract String getActions(): It returns the actions of this Permission object in String format.

Returns:
the actions of this Permission.

7.public PermissionCollection newPermissionCollection(): It returns a new PermissionCollection object.

Returns:
a new PermissionCollection object

8.public String toString(): It returns a string representation of the specified Permission object.

Returns:
string representation of the specified Permission object.

Java




import java.lang.management.ManagementPermission;
import java.security.Permission;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // Creating a new ManagementPermission object with
        // name control
        Permission p = new ManagementPermission("control");
        try {
            // Printing name of the object
            System.out.println("Name: " + p.getName());
            // Printing hash value of the object
            System.out.println("Hashcode: " + p.hashCode());
            // Printing actions of the object
            System.out.println("Actions: "
                               + p.getActions());
            // Converting this managementPermission object
            // to new PermissionCollection object
            System.out.println(
                "As a new PermissionCollection object: "
                + p.newPermissionCollection().toString());
            // Checking if new permissionCollection implies
            // managementPermission object or not
            System.out.println(
                "Implies: "
                + p.newPermissionCollection().implies(p));
        }
        catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}
Output
Name: control
Hashcode: 951543133
Actions: 
As a new PermissionCollection object: java.security.BasicPermissionCollection@5b6f7412 (
)

Implies: false

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :