import java.util.UUID; public class Test { public static void main(String[] args) { UUID uuid = UUID.randomUUID(); System.out.println (uuid); } } 編譯運行輸出: 07ca3dec-b674-41d0-af9e-9c37583b08bb
參考:http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html