Home » Java programming language

Java Package getPackage() method with example

Package Class getPackage() method: Here, we are going to learn about the getPackage() method of Package Class with its syntax and example.
Submitted by Preeti Jain, on November 30, 2019

Package Class getPackage() method

  • getPackage() method is available in java.lang package.
  • getPackage() method is used to search a package by given package name in the caller's ClassLoader instance when the callers ClassLoader instance exists null then the bundles of package loaded by that System ClassLoader instance is searched to determine the named package.
  • getPackage() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • getPackage() method does not throw an exception at the time of returning package.


    public static Package getPackage(String pack_name);


  • String pack_name – represents the fully qualified name of the package.

Return value:

The return type of this method is Package, it returns the name of the given package else it returns null when no package exists from the database.


// Java program to demonstrate the example 
// of Package getPackage(String pack_name) 
// of Package method

public class GetPackage {
    public static void main(String[] args) {
        // Get Package by using getPackage() method
        Package pkg = Package.getPackage("java.util");

        // Get name of the package and
        //stored in a variable pname
        String pname = pkg.getName();

        // Display name of the package
        System.out.print("Package Name: ");


Package Name: java.util

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.