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:
Method |
Description |
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)
{
Permission p = new ManagementPermission( "control" );
try {
System.out.println( "Name: " + p.getName());
System.out.println( "Hashcode: " + p.hashCode());
System.out.println( "Actions: "
+ p.getActions());
System.out.println(
"As a new PermissionCollection object: "
+ p.newPermissionCollection().toString());
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