Jump to Real's How-to Main page

Get a unique identifier

java.rmi.dgc.VMID can generate an identifier. Each new VMID is unique for all Java virtual machines under the following conditions:

The format is :

[2 chars for each byte in 4 byte ip address]:
  [8 char unique string]:
    [16 char from time in hex]:
      [8 char from count]

Code :

public class TestVMID {
 public static void main(String arg[]) {
   System.out.println(new java.rmi.dgc.VMID().toString());
   System.out.println(new java.rmi.dgc.VMID().toString());
   System.out.println(new java.rmi.dgc.VMID().toString());
 }
}

Output :

d578271282b42fce:-2955b56e:107df3fbc96:-8000
d578271282b42fce:-2955b56e:107df3fbc96:-7fff
d578271282b42fce:-2955b56e:107df3fbc96:-7ffe

See also this HowTo


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]