Java. util. UUID

Source: Internet
Author: User

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
  1. Package test;
  2. Import java. util. UUID;
  3. Public class UUIDGenerator {
  4. Public UUIDGenerator (){
  5. }
  6. Public static String getUUID (){
  7. UUID uuid = UUID. randomUUID ();
  8. String str = uuid. toString ();
  9. // Remove the "-" symbol
  10. String temp = str. substring (0, 8) + str. substring (9, 13) + str. substring (14, 18) + str. substring (19, 23) + str. substring (24 );
  11. Return str + "," + temp;
  12. }
  13. // Obtain the specified number of UUID
  14. Public static String [] getUUID (int number ){
  15. If (number <1 ){
  16. Return null;
  17. }
  18. String [] ss = new String [number];
  19. For (int I = 0; I <number; I ++ ){
  20. Ss [I] = getUUID ();
  21. }
  22. Return ss;
  23. }
  24. Public static void main (String [] args ){
  25. String [] ss = getUUID (10 );
  26. For (int I = 0; I <ss. length; I ++ ){
  27. System. out. println ("ss [" + I + "] ====" + ss [I]);
  28. }
  29. }
  30. }


[Java]View plaincopy
  1. Ss [0] ==== 4cdbc040-657a-4847-b266-7e31d9e2c3d9, 4cdbc040657a4847b2667e31d9e2c3d9
  2. Ss [1] ==== 72297c88-109-4c05-9b05-d28bfb11d10b, 72297c881094c059b05d28bfb11d10b
  3. Ss [2] ==== 6d513b6a-69bd-4f79-b94c-d65fc841ea95, 6d513b6a69bd4f79b94cd65fc841ea95
  4. Ss [3] ==== d897a7d3-87a3-4e38-9e0b-71013a6dbe4c, d897a7d387a34e389e0b71013a6dbe4c
  5. Ss [4] ==== 5709f0ba-31e3-42bd-a28d-03485b257c94, 5709f0ba31e342bda28d03485b257c94
  6. Ss [5] ==== 530fbb8c-eec9-48d1-ae1b-5f792daf09f3, 530fbb8ceec948d1ae1b5f792daf09f3
  7. Ss [6] ==== 4bf07297-65b2-45ca-b905-6fc6f2f39158, 4bf0729765b245cab9056fc6f2f39158
  8. Ss [7] ==== 6e5a0e85-b4a0-485f-be54-a758115317e1, 6e5a0e85b4a0485fbe54a758115317e1
  9. Ss [8] ==== 245accec-3c12-4642-967f-e476cef558c4, 245accec3c124642967fe476cef558c4
  10. 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 ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.