Java Class.getPackage()
Syntax
Class.getPackage() has the following syntax.
public Package getPackage()
Example
In the following code shows how to use Class.getPackage() method.
//from www.j av a2 s. co m
public class Main {
public static void main(String[] args) throws Exception {
Class cls = Class.forName("java.lang.Integer");
// returns the name and package of the class
System.out.println("Class = " + cls.getName());
System.out.println("Package = " + cls.getPackage());
}
}
The code above generates the following result.