The java.net.SocketPermisson class represents whether you have permission to access a network via sockets. A SocketPermission consists of a host and a set of actions.
Class Declaration:
public final class SocketPermission extends Permission implements Serializable
Constructor:Constructor Description ManagementPermission(String name) This constructs a ManagementPermission with the specified name. ManagementPermission(String name, String actions) This constructs a new ManagementPermission object.
public SocketPermission(String host, String action):
Used for creating a new object of SocketPermission class with specified actions.
Methods:Method Description equals(object obj) It checks whether the two SocketPermission objects are equal or not. getActions() It returns the actions of this SocketPermission object in String format hashcode() It returns the hash code value for this object. implies(Permission p) It checks whether this SocketPermssion object implies this permission or not. newPermissonCollection() It returns a new PermissionCollection object.
Example:
Java
// Java Program to show the usage of // java.net.SocketPermission Classimport java.io.IOException;import java.net.SocketPermission;import java.security.Permission;import java.security.PermissionCollection; public class Socket { public static void main(String args[]) { try { // getting permission object Permission p = getPermission(); // print actions of permission p System.out.println(p.getActions()); // printing hashcode vlaue of permission p System.out.println(p.hashCode()); // creating a permissionCollection object and // printing it PermissionCollection p1 = p.newPermissionCollection(); System.out.print(p1); } catch (Exception e) { System.err.print("Permission denied"); } } public static Permission getPermission() throws IOException { int port = 3000; String host = "localhost"; return new SocketPermission(host + ":" + port, "Connect,resolve"); }} |
connect,resolve -1204607085 java.net.SocketPermissionCollection@30dae81 ( )
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.


