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