Home » Java programming language

Java System class setSecurityManager() method with example

System class setSecurityManager() method: Here, we are going to learn about the setSecurityManager() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 12, 2019

System class setSecurityManager() method

  • setSecurityManager() method is available in java.lang package.
  • 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() method is a static method so it is accessible with the class name too.
  • setSecurityManager() method does not throw any exception.


    public static void setSecurityManager(SecurityManager sm);


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

Return value:

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


// 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

        // 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");

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


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

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.