Tuesday, August 19, 2008

Generating unique IDs with UUID

The identifiers generated by UUID are actually universally unique identifiers.

Example

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) );
}
}

No comments:

search engine

Custom Search