This class is an immutable representation of 128-bit
Universal Unique
Identifier, or UUID, which serves as an identifier that is (with very
high probability) globally unique. Create a UUID based on random bits
with the randomUUID( ) factory method. Create a
UUID based on the MD5 hash code of an array of bytes with the
nameUUIDFromBytes( ) factory method. Or create a
UUID by parsing a string with the fromString( )
factory method. The standard string format of a UUID is 32
hexadecimal digits, broken into five hyphen-separated groups of 8, 4,
4, 4, and 12 digits. For example:
7cbf3e1a-d521-40ac-87f1-e28b17530f60
Both lowercase and uppercase hex digits are allowed. The
toString( ) method converts a UUID object to a
string using this standard format. You can also create a UUID object
by explicitly passing the 128 bits in the form of two
long values to the UUID( )
constructor, but this option should be used only if you are
intimately familiar with the relevant UUID standards.
The toString( ) and equals( )
methods define the most common operations on a UUID. The
UUID class implements the
Comparable interface and defines an ordering for
UUID objects. Note, however, that the ordering
does not represent any meaningful property, such as generation order,
of the underlying bits.
Various accessor methods provide details about the bits of a
UUID, but these details are rarely useful.
getLeastSignificantBits( ) and
getMostSignificantBits( ) return the bits of a
UUID as two long values. version(
) and variant( ) return the version and
variant of the UUID, which specify the type (random, name-based,
time-based) and bit layout of the UUID. timestamp(
), clockSequence( ), and node(
) return values only for time-based UUIDs that have a
version( ) of 1. Note that the
UUID class does not provide a factory method for
creating a time-based UUID.
Figure 16-67. java.util.UUID
public final class
UUID implements Serializable, Comparable<UUID> {
// Public Constructors
public
UUID (long
mostSigBits , long
leastSigBits );
// Public Class Methods
public static UUID
fromString (String
name );
public static UUID
nameUUIDFromBytes (byte[ ]
name );
public static UUID
randomUUID ( );
// Public Instance Methods
public int
clockSequence ( );
public long
getLeastSignificantBits ( );
public long
getMostSignificantBits ( );
public long
node ( );
public long
timestamp ( );
public int
variant ( );
public int
version ( );
// Methods Implementing Comparable
public int
compareTo (UUID
val );
// Public Methods Overriding Object
public boolean
equals (Object
obj );
public int
hashCode ( );
public String
toString ( );
}