Java Package isSealed() Method



Description

The Java Package isSealed(URL url) method true if this package is sealed with respect to the specified code source url.

Declaration

Following is the declaration for java.lang.Package.isSealed() method

public boolean isSealed(URL url)

Parameters

url − the code source url

Return Value

This method returns true if this package is sealed with respect to url

Exception

NA

Checking a java.lang Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it java.lang package object. Next we've created a URL object with http://www.tutorialspoint.com". Then using isSealed() method, we're checking if package is sealed or not with respect to the given URL.

package com.tutorialspoint;

import java.net.MalformedURLException;
import java.net.URL;

public class PackageDemo {

   public static void main(String[] args) {
      try {
         // get the java lang package
         Package pack = Package.getPackage("java.lang");

         // check if this package is sealed
         URL url = new URL("http://www.tutorialspoint.com");
         System.out.println("" + pack.isSealed(url));
      } catch (MalformedURLException ex) {
         ex.printStackTrace();
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false

Checking a com.tutorialspoint Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it com.tutorialspoint package object. Next we've created a URL object with http://www.tutorialspoint.com". Then using isSealed() method, we're checking if package is sealed or not with respect to the given URL.

package com.tutorialspoint;

import java.net.MalformedURLException;
import java.net.URL;

public class PackageDemo {

   public static void main(String[] args) {
      try {
         // get the java lang package
         Package pack = Package.getPackage("com.tutorialspoint");

         // check if this package is sealed
         URL url = new URL("http://www.tutorialspoint.com");
         System.out.println("" + pack.isSealed(url));
      } catch (MalformedURLException ex) {
         ex.printStackTrace();
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false

Checking a java.util Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it java.util package object. Next we've created a URL object with http://www.tutorialspoint.com". Then using isSealed() method, we're checking if package is sealed or not with respect to the given URL.

package com.tutorialspoint;

import java.net.MalformedURLException;
import java.net.URL;

public class PackageDemo {

   public static void main(String[] args) {
      try {
         // get the java util package
         Package pack = Package.getPackage("java.util");

         // check if this package is sealed
         URL url = new URL("http://www.tutorialspoint.com");
         System.out.println("" + pack.isSealed(url));
      } catch (MalformedURLException ex) {
         ex.printStackTrace();
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false
java_lang_package.htm
Advertisements