Java 26 introduces native support for UUID version 7

0x54MUR411 pts0 comments

UUID (Java SE 26 & JDK 26)

JavaScript is disabled on your browser.

Class UUID

java.lang.Object<br>java.util.UUID

All Implemented Interfaces:<br>Serializable, ComparableUUID>

public final class UUID<br>extends Object<br>implements Serializable, ComparableUUID>

A class that represents an immutable Universally Unique IDentifier (UUID).<br>A UUID represents a 128-bit value.

This class is primarily designed for manipulating Leach-Salz variant UUIDs,<br>but it also supports the creation of UUIDs of other variants.

The layout of a variant 2 (Leach-Salz) UUID is as follows:

The most significant long consists of the following unsigned fields:

0xFFFFFFFF00000000 time_low<br>0x00000000FFFF0000 time_mid<br>0x000000000000F000 version<br>0x0000000000000FFF time_hi

The least significant long consists of the following unsigned fields:

0xC000000000000000 variant<br>0x3FFF000000000000 clock_seq<br>0x0000FFFFFFFFFFFF node

The variant field contains a value which identifies the layout of the<br>UUID. The bit layout described above is valid only for a<br>UUID with a variant value of 2, which indicates the Leach-Salz variant.

See<br>RFC 9562: Universally Unique Identifiers (UUIDs) for the complete specification,<br>including the UUID format, layouts, and algorithms for creating UUIDs.

There are eight defined types of UUIDs, each identified by a version number:<br>time-based (version 1), DCE security (version 2), name-based with MD5 (version 3),<br>randomly generated (version 4), name-based with SHA-1 (version 5), reordered time-based (version 6),<br>Unix epoch time-based (version 7), and custom-defined layout (version 8).

Since:<br>1.5<br>External Specifications

RFC 9562 Universally Unique IDentifiers (UUIDs)

See Also:

Serialized Form

Constructor Summary

Constructors

Constructor

Description

UUID(long mostSigBits,<br>long leastSigBits)

Constructs a new UUID using the specified data.

Method Summary

All MethodsStatic MethodsInstance MethodsConcrete Methods

Modifier and Type

Method

Description

int

clockSequence()

The clock sequence value associated with this UUID.

int

compareTo(UUID val)

Compares this UUID with the specified UUID.

boolean

equals(Object obj)

Compares this object to the specified object.

static UUID

fromString(String name)

Creates a UUID from the string standard representation as<br>described in the toString() method.

long

getLeastSignificantBits()

Returns the least significant 64 bits of this UUID's 128 bit value.

long

getMostSignificantBits()

Returns the most significant 64 bits of this UUID's 128 bit value.

int

hashCode()

Returns a hash code for this UUID.

static UUID

nameUUIDFromBytes(byte[] name)

Static factory to retrieve a type 3 (name based) UUID based on<br>the specified byte array.

long

node()

The node value associated with this UUID.

static UUID

ofEpochMillis(long timestamp)

Creates a type 7 UUID (UUIDv7) UUID from the given Unix Epoch timestamp.

static UUID

randomUUID()

Static factory to retrieve a type 4 (pseudo randomly generated) UUID.

long

timestamp()

The timestamp value associated with this UUID.

String

toString()

Returns a String object representing this UUID.

int

variant()

The variant number associated with this UUID.

int

version()

The version number associated with this UUID.

Methods declared in class Object

clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Modifier and Type

Method

Description

protected Object

clone()

Creates and returns a copy of this object.

protected void

finalize()

Deprecated, for removal: This API element is subject to removal in a future version.<br>Finalization is deprecated and subject to removal in a future<br>release.

final Class

getClass()

Returns the runtime class of this Object.

final void

notify()

Wakes up a single thread that is waiting on this object's<br>monitor.

final void

notifyAll()

Wakes up all threads that are waiting on this object's monitor.

final void

wait()

Causes the current thread to wait until it is awakened, typically<br>by being notified or interrupted.

final void

wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically<br>by being notified or interrupted, or until a<br>certain amount of real time has elapsed.

final void

wait(long timeoutMillis,<br>int nanos)

Causes the current thread to wait until it is awakened, typically<br>by being notified or interrupted, or until a<br>certain amount of real time has elapsed.

Constructor Details

(long,long)"><br>UUID

public UUID(long mostSigBits,<br>long leastSigBits)

Constructs a new UUID using the specified data.<br>mostSigBits is used for the most significant 64 bits of the<br>UUID and leastSigBits becomes the least significant 64 bits of<br>the UUID.

Parameters:<br>mostSigBits - The most significant bits of the UUID<br>leastSigBits - The least significant bits of the UUID

Method Details

randomUUID

public static UUID randomUUID()

Static factory to retrieve a type 4 (pseudo randomly generated) UUID.

The UUID is generated using a cryptographically strong...

uuid long version object value variant

Related Articles