Java 5 has java.util.UUID http://download.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html
- http://jug.safehaus.org/ seems to be popular and is what I’m using. You need to provide the hardware ethernet address on your own for type 1 UUIDs.
- http://johannburkard.de/software/uuid/ seems like an interesting alternative as well. It uses some OS specific utilities to obtain the hardware ethernet address for use in the UUID.
private UUIDGenerator uuidGen = UUIDGenerator.getInstance();
// Generate a type 1 UUID without a network interface reference.
String myUuid1 = uuidGen.generateTimeBasedUUID().toString();
That’s all that is needed to get your UUID to use as a key in your data store.
Next post we’ll look at using JDK 6 to get the network address to use along with the type 1 UUID.