Site icon

Generate unique identifier or UUID or GUID in java (with example)

Program: generate unique identifier or UUID or GUID in java

package org.learn.uuid;

import java.util.UUID;

public class GenerateUUID {
    public static void main(String[] args) {
        UUID uuid = UUID.randomUUID();
        System.out.printf("1. Generated GUID or UUID is : %s", uuid.toString());
        uuid = UUID.randomUUID();
        System.out.printf("\n2. Generated another GUID or UUID : %s", uuid.toString());
    }
}

Output: unique identifier or UUID or GUID in java

1. Generated GUID or UUID is : f9efc66d-7727-4ec9-b628-88f1cab314e8
2. Generated another GUID or UUID : 15a606d5-ea51-4cd9-8342-53f9c6d1c81b
Exit mobile version