Home » Java programming language

Java Package hashCode() method with example

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

Package Class hashCode() method

  • hashCode() method is available in java.lang package.
  • hashCode() method is used to return the hashcode of the package calculated from the package name.
  • hashCode() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • hashCode() method does not throw an exception at the time of returning hashcode of the package.


    public int hashCode();


  • It does not accept any parameter.

Return value:

The return type of this method is int, it returns the hashcode of the package determined by the package name.


// Java program to demonstrate the example of int hashCode()
// of Package method

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

        // Get hashcode of the package by using 
        // hashCode()
        int hc = pkg.hashCode();

        // Display hashcode of the package
        System.out.print("Package hashcode: ");
        System.out.print("pkg.hashCode() = " + hc);


Package hashcode: pkg.hashCode() = -888372146

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.