Home » Java programming language

Java System class identityHashCode() method with example

System class identityHashCode() method: Here, we are going to learn about the identityHashCode() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 14, 2019

System class identityHashCode() method

  • identityHashCode() method is available in java.lang package.
  • identityHashCode() method is used to return the hashcode of the given object – By using this method the value of hashcode will be the same as the value of hashcode by using hashCode() method.
  • Let suppose, if we pass an object that holds null value then in that case, the value of hashCode will be 0.
  • identityHashCode() method is a static method so this method is accessible with the class name too.
  • identityHashCode() method does not throw any exception.

Syntax:

    public static int identityHashCode(Object obj);

Parameter(s):

  • obj – represent the object for which the hashcode is to be returned.

Return value:

The return type of this method is int, it returns the hashcode of the given argument.

Example:

// Java program to demonstrate the example of 
// identityHashCode () method of System Class

import java.lang.*;
import java.io.*;

public class IdentityHashCodeMethod {
    public static void main(String[] args) throws Exception {

        File file1 = new File("Java");
        File file2 = new File("Programming");

        // getting hashcode
        int hcode1 = System.identityHashCode(file1);
        System.out.println(hcode1);

        // getting hashcode
        int hcode2 = System.identityHashCode(file2);
        System.out.println(hcode2);
        
    }
}

Output

E:\Programs>javac IdentityHashCodeMethod.java
E:\Programs>java IdentityHashCodeMethod
1018081122
242131142





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.