자바에서 UUID를 생성하는 방법
- util 안에있는 GUID 클래스의 randomUUID 메소드를 호출하면 간단하게 생성가능.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID; | |
public class Main { | |
public static void main(String[] args) { | |
String uuid = UUID.randomUUID().toString(); | |
System.out.println(uuid); | |
} | |
} |
UUID는 범용 고유 식별자(universally unique identifier)로써,
2f48f241-9d64-4d16-bf56-70b9d4e0e79a 이와같은 형태로 고유한 값을 생성해줍니다.
완벽한 고유값이라는 보장은 없지만 실제 사용시에 중복될 가능성이 거의 없어서
테이블의 key값이나 파일 업로드시 임시 파일명 등으로 쓰일수 있습니다.
자바에서 GUID 를 생성하는 방법을 찾아보면 나오지 않는데 UUID 와 GUID사이에는 차이가 없다고합니다.
(마이크로소프트에서 UUID를 GUID로 부른다고함)