DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Recurrent Workflows With Cloud Native Dapr Jobs
  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • Understanding Java Signals

Trending

  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  • Why We Still Struggle With Manual Test Execution in 2025
  • Build an MCP Server Using Go to Connect AI Agents With Databases
  • Overcoming React Development Hurdles: A Guide for Developers
  1. DZone
  2. Coding
  3. Java
  4. How To Create a UUID in Java?

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.

By 
Gaurav Kukade user avatar
Gaurav Kukade
·
Jan. 02, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.7K Views

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.

Introduction

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?

Example UUID

`df6fdea1-10c3-474c-ae62-e63def80de0b`

How to create UUID in Java?

Creating a Randomly Generated UUID (version 4) is really easy in Java.

UUID class is present in thejava.utilpackage. And it has the static methodrandomUUID()which returns the randomly generated UUID.

The example is given below:

Java
 




x
22


 
1
import java.util.UUID;
2

          
3
/**
4
 * A Java program to create a Randomly Generated UUID i.e. Version 4 UUID
5
 * @author Gaurav Kukade at coderolls.com
6
 *
7
 */
8
public class CreateUUID {
9

          
10
    public static void main(String[] args) {
11

          
12
        // creating random uuid i.e. version 4 UUID
13
        UUID uuid = UUID.randomUUID();
14

          
15
        System.out.println("Printing the randomly generated UUID value......\n");
16

          
17
        System.out.println("uuid: "+uuid);
18

          
19
    }
20

          
21
}



Output: 

Java
 




xxxxxxxxxx
1


 
1
Printing the randomly generated UUID value......
2

          
3
uuid: e3aed661-ccc2-42fd-ad69-734fee350cd2



Get the above code as GitHub Gist.

This article was originally published at coderolls.com/create-uuid-in-java

Java (programming language)

Published at DZone with permission of Gaurav Kukade. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Recurrent Workflows With Cloud Native Dapr Jobs
  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • Understanding Java Signals

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!