SocketPermission equals(Object) in Java

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

Syntax:

boolean java.net.SocketPermission.equals(Object obj)

This method takes one argument. This method checks two SocketPermission objects for equality.

Parameters: One parameter is required for this method.

obj: the object to test for equality with this object.

Returns: true if obj is a SocketPermission, and has the same hostname, port range, and actions as this SocketPermission object. However, the port range will be ignored in the comparison if obj only contains the action, 'resolve'.

Exceptions: NA

Approach

Java

package com.SocketPermission;

import java.net.SocketPermission;

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

        String host = "google.com";
        String action = "connect";
        SocketPermission socketPermission = new SocketPermission(host, action);

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

Output:

true


Some other methods of SocketPermission

SocketPermission(String, String)This method creates a new SocketPermission object with the specified actions. The host is expressed as a DNS name, or as a numerical IP address.

equals(Object)This method checks two SocketPermission objects for equality.

getActions()This method returns the canonical string representation of the actions. Always returns present actions in the following order: connect, listen, accept, resolve.

hashCode()This method returns the hash code value for this object.

implies(Permission)This method checks if this socket permission object "implies" the specified permission.

newPermissionCollection()This method returns a new PermissionCollection object for storing SocketPermission objects.

No comments:

Post a Comment