Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create GUID in java EE

i want to know how to create GUID number in java ee , i am using jboss 4.2.3

like image 244
Mohamed Magdy Avatar asked Aug 02 '10 13:08

Mohamed Magdy


People also ask

How do you create a GUID?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

What is a GUID Java?

Overview. UUID (Universally Unique Identifier), also known as GUID (Globally Unique Identifier) represents a 128-bit long value that is unique for all practical purposes.

How do you generate a random UUID in Java?

In Java, the randomUUID() static method is used to generate a random UUID. The method internally uses SecureRandom class, which provides a cryptographically strong random number generator. Every UUID is associated with a version number. The version number describes how the UUID was generated.


2 Answers

import java.util.UUID;

UUID uuid = UUID.randomUUID();

String randomUUIDString = uuid.toString();
like image 53
Otávio Décio Avatar answered Sep 17 '22 08:09

Otávio Décio


import java.util.UUID;

...
UUID id = UUID.randomUUID();

When identifiers are used solely within a database, their generation should be left to the database itself. See Statement.getGeneratedKeys

UUID Javadoc

like image 36
stacker Avatar answered Sep 20 '22 08:09

stacker