Java.lang.Package.getName() Method


Advertisements


Description

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

Declaration

Following is the declaration for java.lang.Package.getName() method

public String getName()

Parameters

NA

Return Value

This method returns the fully-qualified name of this package as defined in the Java Language Specification, Third Edition 6.5.3, for example, java.lang

Exception

NA

Example

The following example shows the usage of lang.Object.getName() method.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // create a package object for java.lang package
      Package pack = Package.getPackage("java.lang");

      // get the fully qualified name for this package
      System.out.println("" + pack.getName());
   }
}

Let us compile and run the above program, this will produce the following result −

java.lang

java_lang_package.htm

Advertisements