Wednesday, September 24, 2025
HomeLanguagesJavaUUID nameUUIDFromBytes() Method in Java with Examples

UUID nameUUIDFromBytes() Method in Java with Examples

The nameUUIDFromBytes() method of UUID class in Java is generally used to retrieve a third type name based UUID based on the specified byte array. This is used as a static factory method.

Syntax:

public static UUID nameUUIDFromBytes(byte[] byte_name)

Parameters: This method accepts a parameter byte_name which refers to the byte array that is used to construct a UUID.

Return Value: This method returns an UUID instance generated from a specified array.

Below programs illustrate the working of nameUUIDFromBytes() method:

Program 1:




// Java code to illustrate nameUUIDFromBytes() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating a byte array
        byte[] byte_name
            = { 50, 40, 30, 20, 10 };
  
        // Printing the byte[]
        System.out.println("Specified byte array: "
                           + Arrays.toString(byte_name));
  
        // Creating an UUID from byte
        UUID UU_ID
            = UUID
                  .nameUUIDFromBytes(byte_name);
  
        // Displaying the UUID value
        System.out.println("UUID value from byte: "
                           + UU_ID);
    }
}


Output:

Specified byte array: [50, 40, 30, 20, 10]
UUID value from byte: d66541c4-a9db-3308-8c67-bbf87dc0df8b

Program 2:




// Java code to illustrate nameUUIDFromBytes() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating a byte array
        byte[] byte_name
            = { 10, 15, 1, 45, 13, 20, 71 };
  
        // Printing the byte[]
        System.out.println("Specified byte array: "
                           + Arrays.toString(byte_name));
  
        // Creating an UUID from byte
        UUID UU_ID
            = UUID
                  .nameUUIDFromBytes(byte_name);
  
        // Displaying the UUID value
        System.out.println("UUID value from byte: "
                           + UU_ID);
    }
}


Output:

Specified byte array: [10, 15, 1, 45, 13, 20, 71]
UUID value from byte: 15fe1179-e857-306b-ad67-b2388e006c8a
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32316 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6680 POSTS0 COMMENTS
Nicole Veronica
11852 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6794 POSTS0 COMMENTS
Ted Musemwa
7070 POSTS0 COMMENTS
Thapelo Manthata
6751 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS