Java PropertyPermission equals() Method



Description

The java 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 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

Checking Two Same PropertyPermission Instances for Equality Example

The following example shows the usage of Java PropertyPermission equals(Object) method to check a permission object. We've built a PropertyPermission object, and then check the permission to be read.

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");
   }
   
   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");
      }else {
         System.out.println("No permissions on "+path+" for read");
      }
   }
}

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

Has permissions on java.home.usr for read

Checking Two Different PropertyPermission Instances for Equality Example

The following example shows the usage of Java PropertyPermission equals(Object) method to check a permission object. We've built a PropertyPermission object, and then check the permission to write.

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 write permissions
      checkFileWritePermissions("java.home.usr");
   }
   
   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");
      }else {
         System.out.println("No permissions on "+path+" for write");
      }
   }
}

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

No permissions on java.home.usr for write
java_util_propertypermission.htm
Advertisements