September 2019
Intermediate to advanced
816 pages
18h 47m
English
The java.lang.Package class is our main focus when we need to obtain information about a specific package. Using this class, we can find out the package's name, the vendor that implemented this package, its title, the version of the package, and so on.
This class is commonly used to find the name of a package that contains a certain class. For example, the package name of the Integer class can be easily obtained as follows:
Class clazz = Class.forName("java.lang.Integer");Package packageOfClazz = clazz.getPackage();// java.langString packageNameOfClazz = packageOfClazz.getName();
Now, let's find the package name of the File class:
File file = new File(".");Package packageOfFile = file.getClass().getPackage();// java.io ...Read now
Unlock full access