Unlike UUID.randomUUID, nameUUIDFromBytes is deterministic: it derives a version 3 UUID from the given bytes using MD5, so the same input always produces the same identifier, which suits reproducible keys.
byte[] input = "product-42".getBytes(java.nio.charset.StandardCharsets.UTF_8);
UUID first = UUID.nameUUIDFromBytes(input);
UUID second = UUID.nameUUIDFromBytes(input);
System.out.println("Same input, same UUID: " + first.equals(second));
System.out.println("UUID: " + first);
Same input, same UUID: true
UUID: 8cb108b7-2e2b-3534-8417-2867298a8d37
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27