Friday, April 22, 2016

Create a GUID in Java

Some software development tasks need a way to generate unique identifiers. I saw several homegrown solutions, but Java 5 makes the process a breeze. It contains class UUID which can generate type 4 (pseudo randomly generated) unique identifiers. Here is a simple example:
package net.softwaregeek;

import java.util.UUID;

public class UUIDMain {
    public static void main(final String[] args) {
        System.out.println(UUID.randomUUID());
    }
}
The code is self-explanatory. It generates a unique identifier and prints it to console. Class UUID contains several other useful methods which I encourage you to explore on your own.

7 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  2. I have read your blog its very attractive and impressive. I like it your blog. Java Training in Chennai

    ReplyDelete
  3. Appreciating the persistence you put into your blog and detailed information you provide.

    Java Training in Bangalore|

    ReplyDelete
  4. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    http://www.traininginmarathahalli.in/

    ReplyDelete
  5. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site
    "Devops Training in Bangalore"

    ReplyDelete
  6. It’s always so sweet and also full of a lot of fun for me personally and
    my office colleagues to search your blog a minimum of thrice in a
    week to see the new guidance you have got.


    Selenium Training in Bangalore

    ReplyDelete