Java.lang.Package.isCompatibleWith() Method



Description

The java.lang.Package.isCompatibleWith(String desired) method Compare this package's specification version with a desired version. It returns true if this packages specification version number is greater than or equal to the desired version number.

Version numbers are compared by sequentially comparing corresponding components of the desired and specification strings. Each component is converted as a decimal integer and the values compared. If the specification value is greater than the desired value true is returned. If the value is less false is returned. If the values are equal the period is skipped and the next pair of components is compared.

Declaration

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

public boolean isCompatibleWith(String desired)

Parameters

desired − the version string of the desired version.

Return Value

This method returns true if this package's version number is greater than or equal to the desired version number

Exception

NumberFormatException − if the desired or current version is not of the correct dotted form.

Example

The following example shows the usage of lang.Object.isCompatibleWith() method.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // get the java lang package
      Package pack = Package.getPackage("java.lang");

      // check if this package is compatible with version 1.4.6
      System.out.println("" + pack.isCompatibleWith("1.4.6"));
   }
}

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

true
java_lang_package.htm
Advertisements