How To Create a UUID in Java?
In this article, you will see how to create a UUID in Java. We are going to create a Randomly Generated UUID, i.e., version 4 UUID here.
Join the DZone community and get the full member experience.Join For Free
In this article, you will see how to create a UUID in Java.
A UUID, or a universally unique identifier, is a 128-bit number used to identify information in computer systems.
UUID is made of hex digits along with 4 hyphens (-). The length of a UUID is 36 characters.
There are 5 types of UUID, but mostly version 4, i.e., Randomly Generated UUID, is used.
We are going to create the version 4 UUID here.
If you do not want to read, you can watch the short video on How to create UUID in Java?
How to create UUID in Java?
Creating a Randomly Generated UUID (version 4) is really easy in Java.
UUID class is present in the
java.utilpackage. And it has the static method
randomUUID()which returns the randomly generated UUID.
The example is given below:
Get the above code as GitHub Gist.
This article was originally published at coderolls.com/create-uuid-in-java
Published at DZone with permission of Gaurav Kukade. See the original article here.
Opinions expressed by DZone contributors are their own.