Home » Java programming language

Java PropertyPermission newPermissionCollection() Method with Example

PropertyPermission Class newPermissionCollection() method: Here, we are going to learn about the newPermissionCollection() method of PropertyPermission Class with its syntax and example.
Submitted by Preeti Jain, on March 21, 2020

PropertyPermission Class newPermissionCollection() method

  • newPermissionCollection() method is available in java.util package.
  • newPermissionCollection() method is used to create a new PermissionCollection object.
  • newPermissionCollection() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • newPermissionCollection() method does not throw an exception at the time of creating an object.

Syntax:

    public PermissionCollection newPermissionCollection();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is PermissionCollection, it returns new PermissionCollection object.

Example:

// Java program to demonstrate the example 
// of newPermissionCollection() method of 
// PropertyPermission

import java.util.*;
import java.security.*;

public class NewPermissionCollectionOfPropertyPermission {
 public static void main(String arg[]) {
  // Instantiates two PropertyPermission object
  PropertyPermission prop_perm1 = new PropertyPermission("os.version", "write");
  PropertyPermission prop_perm2 = new PropertyPermission("os.name", "read");

  // By using newPermissionCollection() method
  // is to create a new permission collection
  // and add permissions
  PermissionCollection pc = prop_perm1.newPermissionCollection();
  pc.add(prop_perm1);
  pc.add(prop_perm2);

  // By using implies() method isto
  // check whether this PermissionCollection
  // holds the permission write or not
  boolean status = pc.implies(prop_perm1);

  // Display status
  System.out.print("pc.implies(prop_perm1): ");
  System.out.println(status);
 }
}

Output

pc.implies(prop_perm1): true


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.