Syntax
UUID.fromString(text); UUID.randomUUID()Examples
UUID Identifiers
Save as Main.java and run with a Java 17+ JDK: java Main.java.
import java.util.UUID;
public class Main {
public static void main(String[] args) throws Exception {
UUID id = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
System.out.println(id.version());
System.out.println(id.toString());
}
}- Expected output: 4 550e8400-e29b-41d4-a716-446655440000
- The fixed value makes the example repeatable. randomUUID creates a new version-4 UUID when a fresh identifier is needed.
Best practices
- Store UUID values in a consistent representation.
- Validate authorization independently of whether an identifier is difficult to guess.
Runtime & versions
Java Virtual Machine. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Java Language Specification