Java. util. UUID
UUID stands for the universal Unique Identifier, which is a standard for Software construction and also known as the Open Software Foundation (OSF) is a part of the organization in the Distributed Computing Environment (Distributed Computing Environment, DCE) field. The purpose of UUID is to allow all elements in the distributed system to have unique identification information without specifying the identification information through the central control terminal. In this way, each user can create a UUID that does not conflict with others. In this case, duplicate names are not required during database creation. At present, the most widely used UUID is Microsoft's Globally Unique Identifiers (GUIDs, linux ext2/ext3 file system, LUKS encryption partition, GNOME, KDE, Mac OS X, and so on.
The following is an example of UUID generation:
[Java]View plaincopy
- Package test;
- Import java. util. UUID;
- Public class UUIDGenerator {
- Public UUIDGenerator (){
- }
- Public static String getUUID (){
- UUID uuid = UUID. randomUUID ();
- String str = uuid. toString ();
- // Remove the "-" symbol
- String temp = str. substring (0, 8) + str. substring (9, 13) + str. substring (14, 18) + str. substring (19, 23) + str. substring (24 );
- Return str + "," + temp;
- }
- // Obtain the specified number of UUID
- Public static String [] getUUID (int number ){
- If (number <1 ){
- Return null;
- }
- String [] ss = new String [number];
- For (int I = 0; I <number; I ++ ){
- Ss [I] = getUUID ();
- }
- Return ss;
- }
- Public static void main (String [] args ){
- String [] ss = getUUID (10 );
- For (int I = 0; I <ss. length; I ++ ){
- System. out. println ("ss [" + I + "] ====" + ss [I]);
- }
- }
- }
Result:
[Java]View plaincopy
- Ss [0] ==== 4cdbc040-657a-4847-b266-7e31d9e2c3d9, 4cdbc040657a4847b2667e31d9e2c3d9
- Ss [1] ==== 72297c88-109-4c05-9b05-d28bfb11d10b, 72297c881094c059b05d28bfb11d10b
- Ss [2] ==== 6d513b6a-69bd-4f79-b94c-d65fc841ea95, 6d513b6a69bd4f79b94cd65fc841ea95
- Ss [3] ==== d897a7d3-87a3-4e38-9e0b-71013a6dbe4c, d897a7d387a34e389e0b71013a6dbe4c
- Ss [4] ==== 5709f0ba-31e3-42bd-a28d-03485b257c94, 5709f0ba31e342bda28d03485b257c94
- Ss [5] ==== 530fbb8c-eec9-48d1-ae1b-5f792daf09f3, 530fbb8ceec948d1ae1b5f792daf09f3
- Ss [6] ==== 4bf07297-65b2-45ca-b905-6fc6f2f39158, 4bf0729765b245cab9056fc6f2f39158
- Ss [7] ==== 6e5a0e85-b4a0-485f-be54-a758115317e1, 6e5a0e85b4a0485fbe54a758115317e1
- Ss [8] ==== 245accec-3c12-4642-967f-e476cef558c4, 245accec3c124642967fe476cef558c4
- Ss [9] ==== ddd4b5a9-fecd-446c-bd78-63b70bb500a1, ddd4b5a9fe9806cbd7863b70bb500a1
It can be seen that UUID refers to the number generated on a machine, which ensures that all machines in the same time and space are unique. Generally, the platform provides the generated API. According to the standards set by the Open Software Foundation (OSF), ethernet card addresses, nanoseconds, chip ID codes, and many possible numbers are used.
UUID consists of the following parts:
(1) The current date and time. The first part of UUID is related to the time. If you generate a UUID after several seconds and then generate a UUID, the first part is different, the rest are the same.
(2) Clock Sequence
(3) Globally Unique IEEE machine identification number. If there is a nic, it is obtained from the nic mac address, and no Nic is obtained in other ways.
The unique defect of UUID is that the generated result string is long. The most common UUID standard is Microsoft's GUID (Globals Unique Identifiers ). In ColdFusion, you can use the CreateUUID () function to generate a UUID in the format of xxxxxxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16 ), each x is a hexadecimal number in the range of 0-9 or a-f. The standard UUID format is: xxxxxxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12). You can download CreateGUID () UDF from cflib for conversion.
The benefits of using UUID can be reflected in distributed software systems (such as DCE/RPC, COM +, and CORBA), which ensures that the IDS generated by each node are not repeated, with the development of integrated technologies such as WEB Services, the advantages of UUID will become more obvious. According to the specific mechanism used, UUID should not only ensure that they are different from each other, or at least it is very different from any other universal unique identifier generated before January 1, 3400 AD.
A universal unique identifier can also be used to point to most possible objects. Microsoft and some other software companies tend to use globally unique identifiers (GUID), a type of generic unique identifiers that can be used to point to object module objects and other software components. The first universal unique identifier was created in the networked computer system (NCS) and subsequently became the distributed computing environment (DCE) of the Open Software Foundation (OSF ).