UUID: Universal Unique identification:universally unique Identifier; A number generated on a machine that guarantees that all machines in the same time and space are unique.
The GUID is a 128-bit long number, typically represented by a 16 binary. The core idea of the algorithm is to combine the machine's NIC, local time, and a random number to generate the GUID. Theoretically, if a machine produces 10 million GUIDs per second, it can be guaranteed (in a probabilistic sense) that it will not repeat for 3,240 years.
The UUID is a new class in 1.5 that, under Java.util, can produce a globally unique ID.
Package com.mytest;
Import Java.util.UUID;
public class Utest {
publicstatic void Main (string[] args) {
UUID uuid = Uuid.randomuuid ();
SYSTEM.OUT.PRINTLN (UUID);
}
}
The result is: 33efddeb-9b73-49eb-9d59-02c10aa7be9d (the result will not be the same at every moment)
The UUID (universally unique Identifier) Globally unique identifier, which is a number generated on a machine that guarantees that all machines in the same time and space are unique. Based on the standard calculations developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond time, chip ID codes, and many possible numbers are used. A combination of the following: the current date and time (the first part of the UUID is related to the time, if you generate a UUID after a few seconds, the first part is different, the rest is the same), the clock sequence, the globally unique IEEE Machine identification number (if there is a network card, from the network card, No network cards are available in other ways, the only drawback to the UUID is that the resulting string will be longer.
JDK1.5
If the JDK1.5 is used, then the spawning UUID becomes a simple matter, assuming that the JDK implements the UUID:
Java. util. UUID, can be called directly.
1, uuid uuid = Uuid.randomuuid ();
2, String s = Uuid.randomuuid (). toString ();//The primary key ID used to generate the database is very good. 。
If you suspect that the field is too long, you can use string truncation:
3.uuid uuid = Uuid.randomuuid ();
Uuid.tostring (). ReplaceAll ("-", ""). substring (0,6);//This is a six-bit intercept .
# # #其中2和3很适合用来生成数据库的主键
The UUID is made up of a 16-bit number that shows up in the form of such
550e8400-e29b-11d4-a716-446655440000
Java Tool Class UUID