Java System类setSecurityManager()方法及示例

系统类setSecurityManager()方法 (System class setSecurityManager() method)

  • setSecurityManager() method is available in java.lang package.

    setSecurityManager()方法在java.lang包中可用。

  • In setSecurityManager() method, if the security manager is already installed then in that case the given parameter establish a connection as the current security manager else if the given argument is null then in that case the given parameter couldn’t establish a connection as the current security manager then no action will be performed.

    setSecurityManager()方法中 ,如果已经安装了安全管理器,则在这种情况下,给定参数将建立连接作为当前安全管理器;否则,如果给定参数为null,则给定参数将无法建立连接作为当前安全管理器。当前的安全管理器,则不会执行任何操作。

  • setSecurityManager() method is a static method so it is accessible with the class name too.

    setSecurityManager()方法是静态方法,因此也可以使用类名进行访问。

  • setSecurityManager() method does not throw any exception.

    setSecurityManager()方法不会引发任何异常。

Syntax:

句法:

    public static void setSecurityManager(SecurityManager sm);

Parameter(s):

参数:

  • sm(security manager) – represents the security manager if the security manager couldn’t establish a connection previously for the current application.

    sm(安全管理器) –如果安全管理器先前无法为当前应用程序建立连接,则表示安全管理器。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回类型为void ,它不返回任何内容。

Example:

例:

// Java program to demonstrate the example of 
// setSecurityManager () method of System Class.

import java.lang.*;
public class SetSecurityManagerMethod {
    public static void main(String[] args) {
        // Creating an instance of SecurityManager
        SecurityManager sm = new SecurityManager();

        // By using setSecurityManager() method is used to 
        //set the Security Manager
        System.setSecurityManager(sm);


        // By using getSecurityManager() method is used 
        //to get the Security Manager
        sm = System.getSecurityManager();

        // By using conditional statement to check existence 
        //of Security Manager existence

        if (sm == null)
            System.out.println("Security manager couldn’t established");

        else
            System.out.println("Security manager connection is established");
    }
}

Output

输出量

E:\Programs>javac SetSecurityManagerMethod.java
E:\Programs>java SetSecurityManagerMethod
Security manager connection is established


翻译自: https://www.includehelp.com/java/system-class-setsecuritymanager-method-with-example.aspx

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值