Home » Java programming language

Java SecurityManager getClassContext() method with example

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

SecurityManager Class getClassContext() method

  • getClassContext() method is available in java.lang package.
  • getClassContext() method is used to return currently executing stack trace as an array of "Class" type.
  • The number of the methods on the stack is the length of an array and the index[0] element indicates the class name of currently executed method and adjacent index[1] element indicate the class name of currently executed method caller and so..on.
  • getClassContext() 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.
  • getClassContext() method does not throw an exception at the time of Class [] of current execution stack.


    public Class[] getClassContext();


  • It does not accept any parameter.

Return value:

The return type of this method is Class[], it returns current execution stack trace as an array of "Class" types.


// Java program to demonstrate the example 
// of Class[] getClassContext() method of SecurityManager 


public class GetClassContext 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 GetClassContext object
        GetClassContext gc = new GetClassContext();

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

        // By using getContext() method is to return the
        // array of Class context
        Class[] cl = gc.getClassContext();

        //  Display Class context array
        for (int k = 0; k < cl.length; ++k)
            System.out.println("cl[k] = " + cl[k]);


cl[k] = class GetClassContext


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.