Generate Unique ID Java
Before Java 5 generating Unique Id was little strenuous process where people used many different logic to generate it. Here we will use java.util.UUID to generate unique Id.
- GenerateUniqueID.java:
package com.javahonk; import java.util.UUID; public class GenerateUniqueID { public static void main(String[] args) { UUID uuid = UUID.randomUUID(); System.out.println("Generated unique id: " + uuid); } }
- Output:
- For more information on java.util.UUID please visit oracle documentation here