Home » Java programming language

Java SecurityManager checkTopLevelWindow() method with example

SecurityManager Class checkTopLevelWindow() method: Here, we are going to learn about the checkTopLevelWindow() method of SecurityManager Class with its syntax and example.
Submitted by Preeti Jain, on December 18, 2019

SecurityManager Class checkTopLevelWindow() method

  • checkTopLevelWindow() method is available in java.lang package.
  • checkTopLevelWindow() method invokes checkPermission with the AWTPermission("showWindowWithoutWarningBanner") permission.
  • checkTopLevelWindow() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • checkTopLevelWindow() method may throw an exception at the time of showing the window.
    NullPointerException – This exception may throw when the given parameter is null.


    public boolean checkTopLevelWindow(Object e_win);


  • Object e_win – represents the newly created window.

Return value:

The return type of this method is boolean, it returns true when the caller is genuine or trusted to bring the top-level window denoted by the given parameter and window will be shown otherwise it returns false when the calling thread is not genuine or non-trusted but whether the window will be shown or not depend on calling thread.


// Java program to demonstrate the example 
// of boolean checkTopLevelWindow(Object e_win)
// method of SecurityManager 


public class CheckTopLevelWindow extends SecurityManager {
    public static void main(String[] args) {
        // By using setProperty() method is to set the policy property 
        // with security manager
        System.setProperty("", "file:/C:/java.policy");

        // Instantiating a CheckTopLevelWindow object
        CheckTopLevelWindow ctlw = new CheckTopLevelWindow();

        // By using setSecurityManager() method is to set the
        // security manager

        // By using checkTopLevelWindow(Object) method is to //check 
        // that top level window is setor not
        boolean e_win = ctlw.checkTopLevelWindow("Window");

        // Display e_win
        System.out.println("e_win = " + e_win);


e_win = false


Comments and Discussions



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

© some rights reserved.