Java Utility Library

Java.util.UUID Class



Java UUID Class

Java.util package provides an UUID class which represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. It is used for creating random file names, session id in web application, transaction id etc. There are four different basic types of UUIDs: time-based, DCE security, name-based, and randomly generated UUIDs.

Class declaration

The declaration of java.util.UUID class is:

public final class UUID
  extends Object
    implements Serializable, Comparable<UUID>

Here, E is the type of element maintained by the container.

Class Constructor

S.NConstructors & Description
1. UUID(long mostSigBits, long leastSigBits)
Constructs a new UUID using the specified data.

java.util.UUID Methods

The java.util.UUID class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. int clockSequence()
Returns the clock sequence value associated with this UUID.
2. int compareTo(UUID val)
Compares this UUID with the specified UUID.
3. boolean equals(Object obj)
Compares this object to the specified object.
4. static UUID fromString(String name)
Creates a UUID from the string standard representation.
5. long getLeastSignificantBits()
Returns the least significant 64 bits of this UUID's 128 bit value.
6. long getMostSignificantBits()
Returns the most significant 64 bits of this UUID's 128 bit value.
7. int hashCode()
Returns a hash code for this UUID.
8. static UUID nameUUIDFromBytes(byte[] name)
Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.
9. long node()
Returns the node value associated with this UUID.
10. static UUID randomUUID()
Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
11. long timestamp()
Returns the timestamp value associated with this UUID.
12. String toString()
Returns a String object representing this UUID.
13. int variant()
Returns the variant number associated with this UUID.
14. int version()
Returns the version number associated with this UUID.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object