Generate Random UUID in Java

Tags: UUID Random

In this Java core tutorial, we learn how to use java.util.UUID class in Java to generate a random universally unique identifier (UUID).

In the following Java program, we show how to use UUID.randomUUID() static method to generate a new random UUID value.

GenerateRandomUUID.java

import java.util.UUID;

public class GenerateRandomUUID {
    public static void main(String[] args) {

        UUID uuid = UUID.randomUUID();

        String uuidString = uuid.toString();

        System.out.println(uuidString);
    }
}
The output is:
42054a62-3dc6-40e2-b994-a266f280cf37

Happy Coding 😊