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

How to generate GUID in Java

Y2J
Release: 2017-04-26 13:33:56
Original
2625 people have browsed it

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()); }}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template