UUIDs, Why & How ? - DevDummy


Views | Thoughts | Concepts | Techniques

Sunday, November 20, 2016

UUIDs, Why & How ?

As per Wikipedia,
A universally unique identifier (UUID) is an identifier standard used in software construction. A UUID is simply a 128-bit value. The meaning of each bit is defined by any of several variants.

A UUID is a 16-octet (128-bit) number in with digit having hyphens in the form of, 8-4-4-4-12.

Variants and Versions
There are four different basic types of UUIDs: time-based, DCE security, name-based, and randomly generated UUIDs. These types have a version value of 1, 2, 3 and 4, respectively.
However in programming rendomly generated type (version 4) is used mostly. 

Version 4, randomly generated UUIDs have its own specific digit content such as;


Here x is any hexadecimal digit and y is one of 8, 9, a, or b.
Example :

Why UUIDS in programming ?
Specially when you are in a concurrent or distributed environment, when the transactions or the operations are not lablled by a centraliced mechanism, you have to make the each request distinct between others regardless of the external application. 
In this case UUIDs are a great fit which naturally avoids the duplicates ( at lease as per the requirment scope of the application).

java.util.UUID class
UUID generation in Java in very straight forward using  java.util.UUID class:

UUID  randomUUID  =  UUID.randomUUID();

No comments:

Post a Comment