Home > Core Java

java.util.UUID Example in Java

September 27, 2013
java.util.UUID has been introduced from JDK 1.5. UUID is an immutable class that represents universally unique identifier. The important methods of this class is randomUUID, nameUUIDFromBytes etc. A simple example is given below.

UUIDTest.java
import java.util.UUID;
public class UUIDTest {
	public static final void main(String... aArgs){
		UUID id = null;
		for(int i=0;i<5;i++){
			//generate random UUIDs
			id = UUID.randomUUID();
			System.out.println(id);
		}
	  }      
}
 
Output:
f2879fc8-1f16-41f4-b685-8cc7aa4c884f
fcafed14-51cf-4397-ad05-46027a81edf7
7f9c84ed-c4cf-48e2-8825-80ef286c18ca
94811ed3-051c-44a6-98a9-59ef7ce1b004
16a5c97b-9a5c-4f45-bea8-49ce9218839a
comments powered by Disqus



Home    Core Java    Spring    Hibernate    Jquery    My Computer    News    Forum    Quiz    Interview Q & A     Maven     Eclipse IDE

Copyright ©2014 concretepage.com | All rights reserved |Privacy

Developed by : TechWox Corporation