Pages

Saturday, April 11, 2015

Unique IDs/Tokens in java

Generating Unique IDs/Tokens in java.

The following user Java 5

import java.util.UUID;

public class GenerateUUID {
  
  public static final void main(String... aArgs){
    //generate random UUIDs
    UUID idOne = UUID.randomUUID();
    UUID idTwo = UUID.randomUUID();
    log("UUID One: " + idOne);
    log("UUID Two: " + idTwo);
  }
  
  private static void log(Object aObject){
    System.out.println( String.valueOf(aObject) );
  }
} 

Source : http://www.javapractices.com/topic/TopicAction.do?Id=56

No comments:

Post a Comment