Home » Java programming language

Java Class class getProtectionDomain() method with example

Class class getProtectionDomain() method: Here, we are going to learn about the getProtectionDomain() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 19, 2019

Class class getProtectionDomain() method

  • getProtectionDomain() method is available in java.lang package.
  • getProtectionDomain() method is used to return the ProtectionDomain of this class (i.e. ProtectionDomain protects source code by implementing a set of permissions).
  • getProtectionDomain() method is a non-static method, it is accessible with the class objects only and if we try to access the method with the class name then we will get an error.
  • getProtectionDomain() method may throw an exception at the time of returning ProtectionDomain of the class.
    SecurityException : In this exception its checkPermission() method restricts ProtectionDomain when security manager exists.


    public ProtectionDomain getProtectionDomain();


  • It does not accept any parameter.

Return value:

The return type of this method is ProtectionDomain, it returns the ProtectionDomain of the class.


// Java program to demonstrate the example 
// of ProtectionDomain getProtectionDomain() method of Class 

import java.security.*;

public class GetProtectionDomainOfClass {
    public static void main(String[] args) throws Exception {
        // Get Class object
        Class cl = Class.forName("java.util.ArrayList");

        // It return the ProtectionDomain of the class ArrayList
        ProtectionDomain pd = cl.getProtectionDomain();

        // Display ProtectionDomain of the class
        System.out.print("ArrayList ProtectionDomain : ");


ArrayList ProtectionDomain : ProtectionDomain  null
 <no principals>
 [email protected] (
 ("java.security.AllPermission" "<all permissions<" "<all actions>")

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

© https://www.includehelp.com some rights reserved.