|
How to generate a UUID in Java
The following example shows generating a random and named UUID in java.
|
package com.bethecoder.articles.basics.uuid;
import java.util.UUID;
public class UUIDTest {
/**
* @param args
*/
public static void main(String[] args) {
UUID uuid = UUID.randomUUID();
System.out.println(uuid);
uuid = UUID.nameUUIDFromBytes("BE THE CODER".getBytes());
System.out.println(uuid);
}
}
|
| |
It gives the following output,
bbf85cc7-fd66-4ddc-b081-99693f8d9fd0
30034167-ecad-39bc-9c7d-86f1629ca986
|
|