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 *

*
*

  • What I'm Doing...

    • Missing Feature: I wouldn't be surprised if the Kindle reader would allow you to tweet a quote right from an eBook. 2 days ago
    • Money is not only colorblind, it is also color dumb. 3 days ago
    • How can people war their constitutional rights be agreeing to a terms of service they didn't read or understand? 4 days ago
    • iPhone or iMole: whatever data or contact or image you have on your iPhone some hacker, service, API, law enforcement, or app will access. 4 days ago
    • TGIF 5 days ago
    • More updates...

    Posting tweet...

  • Categories