Saturday, September 27, 2025
HomeLanguagesJavaUUID version() Method in Java with Examples

UUID version() Method in Java with Examples

Every UUID has a version number describing the generation of this UUID. The version() method of UUID class in Java is generally used to get version number associated with this UUID.

Syntax:

public int version()

Parameters: This method does not take any parameter.

Return Value: This method returns a int value which is the version number associated with this UUID.

Below programs illustrate the working of version() method:

Program 1:




// Java code to illustrate version() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "58e0a7d7-eebc-11d8-9669-0800200c9a66");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the version number
        System.out.println("The version number is: "
                           + UUID_1.version());
    }
}


Output:

UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The version number is: 1

Program 2:




// Java code to illustrate version() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "5fc03087-d265-11e7-b8c6-83e29cd24f4c");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the version Value
        System.out.println("The version number is: "
                           + UUID_1.version());
    }
}


Output:

UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The version number is: 1
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32323 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11914 POSTS0 COMMENTS
Shaida Kate Naidoo
6807 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6763 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS