To generate UUID in Java we can use the java.util.UUID class. This class was introduced in JDK 1.5. The UUID.randomUUID() method return a UUID object.
A Sample Java Program for Generating Unique IDs :
import java.util.UUID;
public class GeneratingUniqId {
public static void main(String[] args) {
UUID testId1 = UUID.randomUUID();
UUID testId2 = UUID.randomUUID();
System.out.println("UUID One: " + testId1);
System.out.println("UUID Two: " + testId2);
}
}
A Sample Java Program for Generating Unique IDs :
import java.util.UUID;
public class GeneratingUniqId {
public static void main(String[] args) {
UUID testId1 = UUID.randomUUID();
UUID testId2 = UUID.randomUUID();
System.out.println("UUID One: " + testId1);
System.out.println("UUID Two: " + testId2);
}
}