Home » Java programming language

Java FilePermission hashCode() Method with Example

FilePermission Class hashCode() method: Here, we are going to learn about the hashCode() method of FilePermission Class with its syntax and example.
Submitted by Preeti Jain, on April 02, 2020

FilePermission Class hashCode() method

  • hashCode() method is available in java.io package.
  • hashCode() method is used to return the hash code value for this FilePermission.
  • hashCode() 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.
  • hashCode() method does not throw an exception at the time of returning hash code.

Syntax:

    public int hashCode();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is int, it returns the hash code value for this FilePermission object.

Example:

// Java program to demonstrate the example 
// of int hashCode() method 
// of FilePermission

import java.io.*;

public class HashCodeOfFP {
 public static void main(String[] args) throws Exception {
  FilePermission fp1 = null;
  FilePermission fp2 = null;

  try {
   // Instantiates FilePermission fp1 , fp2 
   fp1 = new FilePermission("D:\\includehelp.txt", "read");
   fp2 = new FilePermission("D:\\includehelp.txt", "write");

   // By using hashCode() method is to
   // return the hash code value of the 
   // given FilePermission
   int hc = fp1.hashCode();
   System.out.println("fp1.hashCode(): " + hc);

   hc = fp2.hashCode();
   System.out.println("fp2.hashCode(): " + hc);
  } catch (Exception ex) {
   System.out.println(ex.toString());
  }
 }
}

Output

fp1.hashCode(): 738679569
fp2.hashCode(): -1036327793






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.