Java UUID.node() method example

In this tutorial, You will learn how to get the node value of this UUID. Java UUID.node() method throws UnsupportedOperationException - If this UUID is not a version 1 UUID.

The node value associated with this UUID. The 48 bit node value is constructed from the node field of this UUID. This field is intended to hold the IEEE 802 address of the machine that generated this UUID to guarantee spatial uniqueness.

syntax

public long node()

Returns

The node value of this UUID.

Throws

UnsupportedOperationException - If this UUID is not a version 1 UUID.

Java UUID node() example

  • Initialize the String String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
  • UUID.fromString(name); It creates a UUID from the string standard representation.
  • uuid.version(); It returns the version number of this UUID.
  • uuid.node(); It returns the node value associated with this UUID.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
  
        UUID uuid = UUID.fromString(name);

        System.out.println("The version number of UUID is :-  " + uuid.version());
        System.out.println("The node value :-  " + uuid.node());
    }
}

output

The version number of UUID is :-  1
The node value :-  203238039871480