This article is a detailed analysis and introduction to the method of generating GUID in Java. Friends who need it can refer to it
GUID is a 128-bit long number, generally expressed in hexadecimal. The core idea of the algorithm is to generate a GUID by combining the machine's network card, local time, and a random number. Theoretically, if a machine generates 10,000,000 GUIDs per second, it is guaranteed (in a probabilistic sense) that it will not repeat for 3240 years.
The code is as follows:
package com.cn.str;import java.util.UUID;/** * Create GUID * @author Administrator * */public class CreateGUID { public static final String GenerateGUID(){ UUID uuid = UUID.randomUUID(); return uuid.toString(); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(GenerateGUID()); }}
UUID is a new class added in 1.5. Under java.util, it can be used to generate a so-called globally unique ID
The above is the detailed content of How to generate GUID in Java. For more information, please follow other related articles on the PHP Chinese website!