Javatpoint Logo
Javatpoint Logo

Package getImplementationVersion() method in Java with Examples

The getImplementationVersion() method is a part of the Package class in Java. It is employed to obtain the package's implementation version that matches to the given class. If the version is not supplied or cannot be identified, the function returns null. It also returns a string that reflects the package version.

Syntax:

public String getImplementationVersion()

It signifies that there is no need to give any arguments or parameters to this function when you call it. It operates solely on the Package object on which it is called. The method internally accesses the manifest file of the package to retrieve the implementation version information.

The version of the package is represented by a String value that the getImplementationVersion() method returns. It will be returned as a String if the version is mentioned in the manifest file. If the version is not specified or cannot be determined, the method will return null.

Example1:

ALGORITHM:

Step 1: Import the necessary package java.util.logging.Logger.

Step 2: Define a class PackageExample.

Step 3: In the main method, retrieve the package information for the Logger class using Logger.class.getPackage(). This returns the Package object associated with the Logger class.

Step 4: Call the getImplementationVersion() method on the Package object (pkg) to obtain the implementation version of the package.

Step 5: Store the implementation version in a String variable named version.

Step 6: Print the implementation version to the console.

Implementation:

The implementation of the above steps given below

FileName: PackageExample.java

Output:

The code will print the implementation version to the console if it is given in the manifest file. Otherwise, it will print null.

Implementation version: 1.8.0_212

In this example, the implementation version of the java.util.logging package is specified as 1.8.0_212 in the manifest file. Therefore, the code prints the implementation version accordingly.

Implementation version: null

It indicates that the implementation version is not specified or not available for the package.

Example 2:

ALGORITHM:

Step 1: The main method, which serves as the program's entry point, is contained in the PackageExample class, which is declared.

Step 2: To learn more about the Scanner class's package, use the getPackage() function on the Scanner.class object.

Step 3: To obtain the implementation version of the package, the getImplementationVersion() method is used on the Package object.

Step 4: The retrieved version is stored in the version variable.

Step 5: A conditional statement checks if the version is null or not.

Step 6: If the version is not null, it is printed to the console along with a message.

Step 7: If the version is null, a message stating that no implementation version is specified is printed to the console.

FileName: PackageExample.java

Output:

If the actual implementation version specified in the manifest file

Implementation version: 1.8.0_191

If the implementation version is not specified in the manifest file

No implementation version specified.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA