Java.util.PropertyPermission.equals() Method

Advertisements


Description

The java.util.PropertyPermission.equals(Object obj) method checks if this object is equal to obj. i.e. it has the same name and actions as this object

Declaration

Following is the declaration for java.util.PropertyPermission.equals() method

public boolean equals(Object obj)

Parameters

  • obj -- The object to be checked.

Return Value

This method returns true if given object is equal to this object (i.e. same name and actions).

Exception

NA

Example

The following example shows the usage of java.util.PropertyPermission.equals(Object) method.

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;
   
   public static void main(String[] args) {
      // Build property permissions collection
      permission = new PropertyPermission("java.home.usr", "read");
      
      // Check file read permissions
      checkFileReadPermissions("java.home.usr");
      // Check file write permissions
      checkFileWritePermissions("java.home.usr");
   }

   private static void checkFileReadPermissions(String path) {
      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "read"))) {
         System.out.println("Has permissions on "+path+" for read");
      }
   }
   private static void checkFileWritePermissions(String path) {
      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "write"))) {
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}

Let us compile and run the above program, this will produce the following result:

Has permissions on java.home.usr for read



Advertisements
Advertisements