Java.util.UUID Class

Java.util.UUID Class


The java.util.UUID class represents an immutable universally unique identifier (UUID).Following are the important points about UUID:

  • A UUID represents a 128-bit value.
  • It is used for 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

Following is the declaration for java.util.UUID class:

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

Class constructors

S.N.Constructor & Description
1UUID(long mostSigBits, long leastSigBits)

This constructor constructs a new UUID using the specified data.

Class methods

S.N.Method & Description
1int clockSequence()

This method shows the clock sequence value associated with this UUID.

2int compareTo(UUID val)

This method compares this UUID with the specified UUID.

3boolean equals(Object obj)

This method compares this object to the specified object.

4static UUID fromString(String name)

This method creates a UUID from the string standard representation.

5long getLeastSignificantBits()

This method returns the least significant 64 bits of this UUID’s 128 bit value.

6long getMostSignificantBits()

This method returns the most significant 64 bits of this UUID’s 128 bit value.

7int hashCode()

This method returns a hash code for this UUID.

8static UUID nameUUIDFromBytes(byte[] name)

Static factory to retrieve a type 3(name based) UUID based on the specified byte array.

9long node()

This method returns the node value associated with this UUID.

10static UUID randomUUID()

Static factory to retrieve a type 4(pseudo randomly generated) UUID.

11long timestamp()

This method returns the timestamp value associated with this UUID.

12String toString()

This method returns the String object representing this UUID.

13int variant()

This method returns the variant number associated with this UUID.

14int version()

This method removes the version number associated with this UUID.

Methods inherited

This class inherits methods from the following classes:

  • java.util.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.