Java.lang Package Classes

Java Package - getSpecificationVersion() Method



The java.lang.Package.getSpecificationVersion() method returns the version number of the specification that this package implements. This version string must be a sequence of nonnegative decimal integers separated by "."'s and may have leading zeros. When version strings are compared the most significant numbers are compared.

Syntax

public String getSpecificationVersion()

Parameters

No parameter is required.

Return Value

Returns the specification version, null is returned if it is not known.

Exception

NA.

Example:

The example below shows how to use java.lang.Package.getSpecificationVersion() method.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //create a java util package object
    Package p = Package.getPackage("java.util");

    //print the version specification of this package
    System.out.println(p.getSpecificationVersion());
  }
}

The possible output of the above code could be:

1.8

❮ Java.lang - Package