Topics Index

Demonstration of getName and getImplementationVersion methods - Java Example Program

Demonstration of getName and getImplementationVersion methods
class PackageClassDemo
    public static void main(String arg[])
        // Get all the packages that this program is currently aware of.
        Package[] pkgs = Package.getPackages();    // LINE A
        // Display related information about each of these packages in pkgs array
        for( int i = 0; i < pkgs.length; i++ )
            System.out.println( pkgs[i].getName() + " ---> " +
                                    pkgs[i].getImplementationVersion() );

javax.swing.tree ---> 1.7.0_51
sun.util.resources ---> 1.7.0_51 ---> 1.7.0_51
sun.awt.image ---> 1.7.0_51
sun.reflect.misc ---> 1.7.0_51


Output is very long. Only a part of it is shown here.
Here, we are collecting the package info. known to this class in a Package array using getPackages() method (LINE A). Then, we are iterating over this array and displaying corresponding name and version info. of each package.

  • Consider the above program again. Try to use getImplementationTitle() and getImplementationVendor() methods as well in the SOP statement and observe the related info. displayed by these methods.
  • Also try to use getSpecificationTitle(), getSpecificationVendor() and getSpecificationVersion() methods in the same way.
  • Try to obtain information related to a specific package, say javax.swing, by passing it as an argument to getPackage() method as shown earlier.

© meritcampus 2019

All Rights Reserved.

Open In App