A brief introduction to java UUID.randomUUID()

UUID means Universally Unique Identifier (Universally Unique Identifier), which is a standard for software construction. It is also organized by the Open Software Foundation (OSF) in the field of Distributed Computing Environment (DCE). a part. The purpose of UUID is to allow all elements in a distributed system to have unique identification information, without the need to specify identification information through a central control terminal. In this way, everyone can create a UUID that does not conflict with others. In this case, there is no need to consider the problem of name duplication during database creation. Currently, the most widely used UUID is Microsoft's Globally Unique Identifiers (GUIDs), and other important applications include Linux ext2/ext3 file system, LUKS encrypted partition, GNOME, KDE, Mac OS X, etc.

UUID.randomUUID().toString() is a method provided by javaJDK to automatically generate a primary key. UUID (Universally Unique Identifier) ​​refers to a number generated on a machine. It is guaranteed to be unique to all machines in the same time and space. It is composed of a sixteen-digit number and is represented form. A combination of the following parts: current date and time (the first part of UUID is related to time, if you generate a UUID after a few seconds after generating a UUID, the first part is different, and the rest are the same), clock Sequence, the globally unique IEEE machine identification number (if there is a network card, get it from the network card, if there is no network card to obtain it in other ways), the only drawback of UUID is that the resulting string will be relatively long.

/**
 * 	UUID对象测试
 */
@org.junit.Test
public void UUIDTest() {
    
    
	String uuid = UUID.randomUUID().toString();
	System.out.println(uuid);//9d9a0568-1af7-4fa2-aff7-eb838bd78567
}

Guess you like

Origin blog.csdn.net/weixin_43088443/article/details/112971205
Recommended