Java Reflection - 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.

//w  w w  . j a va 2  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.