Skip to content
Fabio Lima edited this page Aug 14, 2021 · 28 revisions

UUID Creator

A Java library for generating and handling RFC-4122 UUIDs.

RFC-4122 UUIDs:

  • Version 1: Time-based;
  • Version 2: DCE Security;
  • Version 3: Name-based (MD5);
  • Version 4: Random-based;
  • Version 5: Name-based (SHA1);
  • Version 6: Time-ordered (proposed).

Non-standard GUIDs:

  • Prefix COMB: combination of the creation millisecond (prefix) with random bytes;
  • Suffix COMB: combination of the creation millisecond (suffix) with random bytes;
  • Short Prefix COMB: combination the creation minute (prefix) with random bytes;
  • Short Suffix COMB: combination the creation minute (suffix) with random bytes.

How to Use

No time to read

This library was designed to be easy to use. The only things you have to know are what a UUID is and what type you need.

If you just want a random UUID, which is the most common case, use this single line of code:

UUID uuid = UuidCreator.getRandomBased();

Or if you want a UUID that is based on creation time, use this line of code:

UUID uuid = UuidCreator.getTimeBased();

Or if you want a UUID that is ordered by creation time, use this line:

UUID uuid = UuidCreator.getTimeOrdered();

All UUID types can be generated from the facade UuidCreator. If you have a special requirement that is not covered by the facade, you can read the rest of this document or check the source code.

The module name for JDK9+ is the package name: com.github.f4b6a3.uuid.

The generators are thread-safe.

Maven dependency

Add these lines to your pom.xml:

<!-- https://search.maven.org/artifact/com.github.f4b6a3/uuid-creator -->
<dependency>
  <groupId>com.github.f4b6a3</groupId>
  <artifactId>uuid-creator</artifactId>
  <version>3.7.3</version>
</dependency>

See more options in maven.org.

Clone this wiki locally