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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.