Package getName() method in Java with Examples Last Updated : 21 Jun, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The getName() method of java.lang.Package class is used to get the name of this package. The method returns the name of the package as a String.Syntax: public String getName() Parameter: This method does not accept any parameter.Return Value: This method returns the name of the package as a String.Below programs demonstrate the getName() method.Example 1: Java // Java program to demonstrate getName() method public class Test { public static void main(String[] args) { // returns the Package object // for this package Package myPackage = Package.getPackage("java.lang"); System.out.println( "Package represented by myPackage: " + myPackage.toString()); // Get the name of myPackage // using getName() method System.out.println("Name of myPackage: " + myPackage.getName()); } } Output: Package represented by myPackage: package java.lang, Java Platform API Specification, version 1.8 Name of myPackage: java.lang Example 2: Java // Java program to demonstrate getName() method public class Test { public static void main(String[] args) { // returns the Package object // for this package Package myPackage = Package.getPackage("java.io"); System.out.println( "Package represented by myPackage: " + myPackage.toString()); // Get the name of myPackage // using getName() method System.out.println("Name of myPackage: " + myPackage.getName()); } } Output: Package represented by myPackage: package java.io, Java Platform API Specification, version 1.8 Name of myPackage: java.io Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Package.html#getName-- Comment More infoAdvertise with us Next Article Package getName() method in Java with Examples G guptayashgupta53 Follow Improve Article Tags : Java Java-lang package Java-Functions java.lang.Package Class Practice Tags : Java Similar Reads Package getPackages() method in Java with Examples The getPackages() method of java.lang.Package class is used to get the Packages defined by the caller's class loader. The method returns the packages as an array of Package objects. Syntax: public boolean getPackages(String desiredVersion) Parameter: This method does not accept any parameter. Return 3 min read Provider getName() method in Java with Examples The getName() method of java.security.Provider class is used to return the name of this provider. Syntax: public String getName() Return Value: This method returns the name of this provider. Below are the examples to illustrate the getName() method: Example 1: Java // Java program to demonstrate // 2 min read Path getName(int) method in Java with Examples The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a di 2 min read Path getNameCount() method in Java with Examples The Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a directo 2 min read Class getName() method in Java with Examples The getName() method of java.lang.Class class is used to get the name of this entity. This entity can be a class, an array, an interface, etc. The method returns the name of the entity as a String.Syntax: public String getName() Parameter: This method does not accept any parameter.Return Value: This 1 min read Like