UUID
/ GUID (Universally / Globally Unique IDentifier) are frequently use in programming. Some of its usage are for creating random file names, session id in web application, transaction id and for record's primary keys in database replacing the sequence or auto generated number.
To generate UUID
in Java we can use the java.util.UUID
class. This class was introduced in JDK 1.5
import java.util.UUID;
public class RandomStringUUID {
public static void main(String[] args) {
//
// Creating a random UUID (Universally unique identifier).
//
UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString();
System.out.println("Random UUID String = " + randomUUIDString);
System.out.println("UUID version = " + uuid.version());
System.out.println("UUID variant = " + uuid.variant());
}
}
Below is the output.....
Random UUID String = 7dc53df5-703e-49b3-8670-b1c468f47f1f
UUID version = 4
UUID variant = 2
Monday, March 5, 2012
How do I generate UUID / GUID in java?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment