Home » Java programming language

Java System class getSecurityManager() method with example

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

System class getSecurityManager() method

  • getSecurityManager() method is available in java.lang package.
  • getSecurityManager() method is used to return the security manager if exists else it returns null if the security manager couldn't establish for the current application.
  • getSecurityManager() method is a static method so this method is accessible with the class name too.
  • The return type of this method is SecurityManager so it returns the security manager only when a security manager is currently established for the current interface and it returns null when a security manager is not establishing for the current application.
  • getSecurityManager() method does not throw any exception.

Syntax:

    public static SecurityManager getSecurityManager();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is SecurityManager, it returns the security manager only when a security manager is currently established for the current interface and it returns null when the security manager is not establishing for the current application.

Example:

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

import java.lang.*;

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

        SecurityManager smgr = System.getSecurityManager();

        if (smgr != null) {
            smgr.checkExit(0);
        } else {

            System.out.println("Security manager is null");
        }

    }
}

Output

E:\Programs>javac GetSecurityManagerMethod.java
E:\Programs>java GetSecurityManagerMethod
Security manager is null






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.