class MyClass { public static void main(String[] args) { System.out.println(MyClass.class.getPackage()); } }
class MyPackage { public static void main(String[] args){ Package pckg = MyPackage.class.getPackage(); System.out.println("Package name:\t" + pckg.getName()); System.out.println("Specification title:\t" + pckg.getSpecificationTitle()); System.out.println("Specification version:\t" + pckg.getSpecificationVersion()); System.out.println("Specification vendor:\t" + pckg.getSpecificationVendor()); System.out.println("Implementation title:\t" + pckg.getImplementationTitle()); System.out.println("Implementation version:\t" + pckg.getImplementationVersion()); System.out.println("Implementation vendor:\t" + pckg.getImplementationVendor()); } }Output: Package name: MyPackage Specification title: null Specification version: null Specification vendor: null Implementation title: null Implementation version: null Implementation vendor: null In this example, we create a MyPackage class and use the getPackage() method to get the package of the class. We also use other methods available in the Package class to get information about the package such as specification title, implementation title, etc. Package library is a group of classes that are related and are developed for a specific purpose. It can be determined by looking at the package structure, naming conventions, and documentation. For example, if the package name starts with "java.", it is part of the Java standard library package. If the package name contains "com." or "org.", it is likely a third-party library package.