tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Articles > Java > Basics > How to generate a UUID in Java

How to generate a UUID in Java 

The following example shows generating a random and named UUID in java.

File Name  :  
com/bethecoder/articles/basics/uuid/UUIDTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.articles.basics.uuid;

import java.util.UUID;

public class UUIDTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    UUID uuid = UUID.randomUUID();
    System.out.println(uuid);
    
    uuid = UUID.nameUUIDFromBytes("BE THE CODER".getBytes());
    System.out.println(uuid);
  }

}
   

It gives the following output,
bbf85cc7-fd66-4ddc-b081-99693f8d9fd0
30034167-ecad-39bc-9c7d-86f1629ca986



 
  


  
bl  br