How to generate a UUID or GUID in Java

This example shows how to generate a UUID (Universally Unique Identifier) or as it is sometimes called a GUID (Globally Unique Identifier).
The UUID class has a static factory method to retrieve a type 4 (pseudo randomly generated) UUID.
The UUID value returned from the factory method is immutable and generated using a cryptographically strong pseudo random number generator.

There exists different variations of these identifiers, and the one handled by the methods of the UUID class is a so-called Leach-Salz variant, but the UUID class has constructors to create any type of UUID.

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.

The output from the code above is:

Search for more Java info on this site here:
Custom Search

Please type any questions here.