Create Universally Unique ID in Java

For the longest time I’ve used java.rmi.server.UID to create a unique ID in a application. We enhanced the UID class to fit our needs and to format the ID to the standard format but unfortunately we found that within a process, we were generating duplicate IDs if we created more than a certain amount. It didn’t take much to remedy the problem since Java introduced java.util.UUID in Java 1.5.

To create a universally unique ID in Java 1.5 or greater just call the static randomUUID method on the UUID class.

UUID.randomUUID().toString()

UUID has a wider range of possible values that I’m not concern of duplicate values or collisions for my application.

Related posts:

  1. Java Five-Oh #2: Static Import
  2. Class HighLite Collections
  3. Print a PDF Document in Java
  4. Class HighLite Calendar
  5. CommunityOne 2007: Lunch with the Java Posse

This entry was posted in Java, TechKnow and tagged , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*