Java.lang Package Classes

Java Package - getName() Method



The java.lang.Package.getName() method returns the name of this package.

Syntax

public String getName()

Parameters

No parameter is required.

Return Value

Returns the fully-qualified name of this package as defined in section 6.5.3 of The Java Language Specification, for example, java.lang

Exception

NA.

Example:

In the example below, the java.lang.Package.getName() method is used to get the name of the given package.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //create a java util package object
    Package p = Package.getPackage("java.util");

    //print the fully-qualified name of this package
    System.out.println(p.getName());
  }
}

The output of the above code will be:

java.util

❮ Java.lang - Package