Package is collection of classes , interfaces and sub packages. Package must be a first statement of a class. To get package details getPackage() method is given in java.lang.Class . getPackage() method returns Package. Package is a class presented in java.lang package. See the below example for better understanding .

package com.java;

import java.lang.reflect.Method;

class Sample
{
    public static void main(String[] args) throws Exception
    {
        Class c1=Class.forName("com.java.Sample");
        Package p=c1.getPackage();
        System.out.println(p.getName());
    }
}

/* 

Output :

com.java

*/