Home » Java programming language

Java Package getPackages() method with example

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

Package Class getPackages() method

  • getPackages() method is available in java.lang package.
  • getPackages() method is used to return all the packages recently for the callers ClassLoader instance when the caller ClassLoader instance is the bootstrap ClassLoader instance which may be denoted by null in some deployments so the only packages similar loaded by bootstrap loader instance will be returned.
  • getPackages() 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.
  • getPackages() method does not throw an exception at the time of return packages.


    public static Package[] getPackages();


  • It does not accept any parameter.

Return value:

The return type of this method is Package[], it returns san array of packages for the caller's ClassLoader instance otherwise it returns 0 when no package exists.


// Java program to demonstrate the example 
// of Package[] getPackages() of Package method

public class GetPackages {
    public static void main(String[] args) {
        // Get Packages by using getPackages() method
        Package[] pkg = Package.getPackages();

        // Display name of the packages 
        System.out.print("Package Name: ");
        for (int i = 0; i < pkg.length; ++i)


Package Name:


Comments and Discussions



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

© some rights reserved.