Generate UUID

d2017916-0f35-4d7a-b3ad-8765c5f65889

🔑 What is a UUID?

A Universally Unique Identifier (UUID) is a 128-bit value used to uniquely identify data across systems.

📐 Length

A UUID is 36 characters long (32 hex digits + 4 hyphens), e.g. 550e8400-e29b-41d4-a716-446655440000.

⚡ Versions

Common types include v1 (time-based), v3/v5 (namespace + hash), and v4 (random, most used today).

🌍 Why UUIDs?

They avoid ID collisions across distributed systems, unlike simple auto-increment IDs in databases.

🛡️ Security

UUIDs are unique but not cryptographically secure. Use them as identifiers, not as secrets or tokens.

🛠️ Common Use Cases

UUIDs are widely used in databases, API keys, session identifiers, distributed systems, and file names.

🎲 Random vs. Deterministic

UUID v4 is generated randomly, making it highly unpredictable. UUID v3 and v5 are deterministic — the same input will always produce the same UUID.

Use v4 for randomness, v3/v5 for consistency (like generating the same ID from a namespace).

🧩 UUID in Java Example


import java.util.UUID;

public class UuidExample {
    public static void main(String[] args) {
        UUID uuid = UUID.randomUUID();
        System.out.println("Generated UUID: " + uuid);
    }
}
        

Java’s UUID class makes it simple to generate v4 UUIDs directly.

⚖️ Limitations & Alternatives

UUIDs are larger than integers and may impact indexing in databases. Alternatives include ULIDs (lexicographically sortable) or Snowflake IDs (Twitter).

Choose based on your need for uniqueness, ordering, or efficiency.

❓ Frequently Asked Questions