URLPermission hashCode() in Java

hashCode(): This method is available in the java.net.URLPermission class of Java.

Syntax:

int java.net.URLPermission.hashCode()

This method returns a hashcode calculated from the hashcode of the actions String and the url string.

Parameters: NA

Returns: a hash code value for this object.

Exceptions: NA

Approach

Java

package com.URLPermission;

import java.net.URLPermission;

public class URLPermissionhashCode {
    public static void main(String[] args) {

        String url = "https://beingcodeexpert.blogspot.com/";
        String actions = "read";
        URLPermission urlPermission = new URLPermission(url, actions);

        System.out.println(urlPermission.hashCode());
    }
}

Output:

-793362237


Some other methods of URLPermission class

URLPermission(String): This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")

URLPermission(String, String): This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers.

equals(Object): his method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.

getActions(): This method returns the normalized method list and requests a header list, in the form: "method-names: header-names".

hashCode(): This method returns a hashcode calculated from the hashcode of the actions String and the url string.

implies(Permission): This method checks if this URLPermission implies some of the permissions.

URLPermission getActions() in Java

getActions(): This method is available in the java.net.URLPermission class of Java.

Syntax:

String java.net.URLPermission.getActions()

This method returns the normalized method list and requests a header list, in the form: "method-names: header-names"

where method-names are the list of methods separated by commas and header-names are the list of permitted headers separated by commas. There is no white space in the returned String. If header-names is empty then the colon separator may not be present.

Parameters: NA

Returns: the actions of this Permission.

Exceptions: NA

Approach

Java

package com.URLPermission;

import java.net.URLPermission;

public class URLPermissiongetActions {
    public static void main(String[] args) {

        String url = "https://beingcodeexpert.blogspot.com/";
        String actions = "read";
        URLPermission urlPermission = new URLPermission(url, actions);

        System.out.println(urlPermission.getActions());
    }
}

Output:

READ:


Some other methods of URLPermission class

URLPermission(String): This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")

URLPermission(String, String): This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers.

equals(Object): his method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.

getActions(): This method returns the normalized method list and requests a header list, in the form: "method-names: header-names".

hashCode(): This method returns a hashcode calculated from the hashcode of the actions String and the url string.

implies(Permission): This method checks if this URLPermission implies some of the permissions.

URLPermission equals(Object) in Java

equals(Object): This method is available in the java.net.URLPermission class of Java.

Syntax:

boolean java.net.URLPermission.equals(Object p)

This method takes one argument. This method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.

Parameters: One parameter is required for this method.

p: the object we are testing for equality with this object.

Returns: true if both Permission objects are equivalent.

Exceptions: NA

Approach

Java

package com.URLPermission;

import java.net.URLPermission;

public class URLPermissionequals {
    public static void main(String[] args) {

        String url = "https://beingcodeexpert.blogspot.com/";
        String actions = "read";
        URLPermission urlPermission = new URLPermission(url, actions);

        System.out.println(urlPermission.equals(urlPermission));
    }
}

Output:

true


Some other methods of URLPermission class

URLPermission(String): This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")

URLPermission(String, String): This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers.

equals(Object): his method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.

getActions(): This method returns the normalized method list and requests a header list, in the form: "method-names: header-names".

hashCode(): This method returns a hashcode calculated from the hashcode of the actions String and the url string.

implies(Permission): This method checks if this URLPermission implies some of the permissions.

URLPermission URLPermission(String, String) in Java

URLPermission(String, String): This method is available in the java.net.URLPermission class of Java.

Syntax:

java.net.URLPermission.URLPermission(String url, String actions)

This method takes two arguments. This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers. The name of the permission is the url string it was created with.

Only the scheme, authority, and path components of the url are used internally. Any fragment or query components are ignored. The permissions action string is as specified above.

Parameters: Two parameters are required for this method.

url: the url string.

actions: the actions string.

Throws:

1. IllegalArgumentException - if url is invalid or if actions contain white space.

Approach 1: When no exception

Java

package com.URLPermission;

import java.net.URLPermission;

public class URLPermission2 {
    public static void main(String[] args) {

        String url = "https://beingcodeexpert.blogspot.com/";
        String actions = "read";
        URLPermission urlPermission = new URLPermission(url, actions);

        System.out.println(urlPermission);
    }
}

Output:

("java.net.URLPermission" "https://beingcodeexpert.blogspot.com/" "READ:")


Approach 2: IllegalArgumentException

Java

package com.URLPermission;

import java.net.URLPermission;

public class URLPermission2 {
    public static void main(String[] args) {

        String url = "https://beingcodeexpert.blogspot.com/";
        String actions = "read   ";
        URLPermission urlPermission = new URLPermission(url, actions);

        System.out.println(urlPermission);
    }
}

Output:

Exception in thread "main" java.lang.IllegalArgumentException: White space not allowed in methods: "read " at java.base/java.net.URLPermission.normalizeMethods(URLPermission.java:417) at java.base/java.net.URLPermission.init(URLPermission.java:218) at java.base/java.net.URLPermission.<init>(URLPermission.java:182) at com.URLPermission.URLPermission2.main(URLPermission2.java:10)


Some other methods of URLPermission class

URLPermission(String): This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")

URLPermission(String, String): This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers.

equals(Object): his method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.

getActions(): This method returns the normalized method list and requests a header list, in the form: "method-names: header-names".

hashCode(): This method returns a hashcode calculated from the hashcode of the actions String and the url string.

implies(Permission): This method checks if this URLPermission implies some of the permissions.