Java Class getPackageName() Method

21 Mar 2025 | 1 min read

The getPackageName() method of java Class class is used to get the fully qualified name of the package. If no package name is specified, then it returns an empty string.

Syntax

Parameter

No parameter is passed.

Returns

Return package name as a string.

Throws

NA

Example 1

Output:

 Class ::: java.lang.Integer.......... Package ::: package java.lang, Java Platform API Specification, version 1.8 Package Name ::: package java.lang, Java Platform API Specification, version 1.8 

Example 2

Output:

 Class Package1 Name::package Class java.util Package2 Name::package Class 
 
Next TopicJava Class