Class getPackage() method in Java with Examples Last Updated : 27 Jan, 2022 Comments Improve Suggest changes Like Article Like Report The getPackage() method of java.lang.Class class is used to get the package of this entity. This entity can be a class, an array, an interface, etc. The method returns the package of this entity.Syntax: public Package getPackage() Parameter: This method does not accept any parameter.Return Value: This method returns the package of this entity.Below programs demonstrate the getPackage() method.Example 1: Java // Java program to demonstrate getPackage() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for this class Class myClass = Class.forName("Test"); System.out.println("Class represented by myClass: " + myClass.toString()); // Get the Package of myClass // using getPackage() method System.out.println("Package of myClass: " + myClass.getPackage()); } } Output: Class represented by myClass: class Test Package of myClass: null Example 2: Java // Java program to demonstrate getPackage() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object Class myClass = Class.forName("java.lang.String"); // Get the package of myClass // using getPackage() method System.out.println("Package of myClass: " + myClass.getPackage()); } } Output: Package of myClass: package java.lang, Java Platform API Specification, version 1.8 Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#getPackage-- Comment More infoAdvertise with us Next Article Class getPackage() method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class getPackageName() method in Java with Examples The getPackageName() method of java.lang.Class class is used to get the package name of this entity. This entity can be a class, an array, an interface, etc. The method returns the package name of this entity as a String.Syntax:Â Â public String getPackageName() Parameter: This method does not accept 2 min read Class getClasses() method in Java with Examples The getClasses() method of java.lang.Class class is used to get the classes of this class, which are the class and interfaces that are public and its members. The method returns the classes of this class in the form of array of Class objects. Syntax: public Class[] getClasses() Parameter: This metho 2 min read Class getModule() method in Java with Examples The getModule() method of java.lang.Class class is used to get the module of this entity. This entity can be a class, an array, an interface, etc. The method returns the module of the entity.Syntax:Â Â public Module getModule() Parameter: This method does not accept any parameter.Return Value: This m 2 min read Class getClassLoader() method in Java with Examples The getClassLoader() method of java.lang.Class class is used to get the classLoader of this entity. This entity can be a class, an array, an interface, etc. The method returns the classLoader of this entity.Syntax: public ClassLoader getClassLoader() Parameter: This method does not accept any parame 1 min read Class getMethods() method in Java with Examples The getMethods() method of java.lang.Class class is used to get the methods of this class, which are the methods that are public and its members or the members of its member classes and interfaces. The method returns the methods of this class in the form of an array of Method objects. Syntax: public 2 min read Like