Home  >  Article  >  Java  >  How to generate GUID in Java

How to generate GUID in Java

Y2J
Y2JOriginal
2017-04-26 13:33:562554browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn