How to get Package information for a given class in java

Example

package com.pretech;
public class PackageInfoExample {
	public static void main(String[] args) {
		Class<String> clazz = String.class;
		Package pack = clazz.getPackage();
		System.out.println(pack);
		System.out.println(pack.getImplementationTitle());
		System.out.println(pack.getName());
		System.out.println(pack.getSpecificationTitle());
	}
}

Output



package java.lang, Java Platform API Specification, version 1.7
Java Runtime Environment
java.lang
Java Platform API Specification


No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts