Java Uuid Generator (JUG) is a library for generating all (3) types of UUIDs on Java. See (http://github.com/tlaukkan/mono-uuid-generator) for C#-based sister project!
JUG is a set of Java classes for working with UUIDs: generating UUIDs using any of standard methods, outputting efficiently, sorting and so on. It generates UUIDs according to the UUID specification (RFC-4122) (also see Wikipedia UUID page for more explanation)
JUG was written by Tatu Saloranta ([email protected]) originally in 2002 and has been updated over years. In addition, many other individuals have helped fix bugs and implement new features: please see
release-notes/CREDITSfor the complete list.
JUG is licensed under Apache License 2.0.
JUG can be used as a command-line tool (via class 'com.fasterxml.uuid.Jug`), or as a pluggable component.
Maven coordinates are:
com.fasterxml.uuid java-uuid-generator 4.0
The only dependency for JUG is the logging library:
log4jis used, optionally (runtime dependency)
slf4jAPI is used: logging implementation to be provided by calling application
3.2.0, JUG defines JDK9+ compatible
module-info.class, with module name of
For direct downloads, check out Project Wiki.
Generation itself is done by first selecting a kind of generator to use, and then calling its
generate()method, for example:
UUID uuid = Generators.randomBasedGenerator().generate(); UUID uuid = Generators.timeBasedGenerator().generate();
If you want customize generators, you may also just want to hold on to generator instance, for example:
java TimeBasedGenerator gen = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); UUID uuid = gen.generate(); UUID anotherUuid = gen.generate();
Generators are fully thread-safe, so a single instance may be shared among multiple threads.
JavaDocs for project can be found from Project Wiki.
JUG versions 3.1 and later require JDK 1.6 to work, mostly to be able to access local Ethernet MAC address. Earlier versions (3.0 and before) worked on 1.4 (which introduced
java.util.UUIDhas flawed implementation of
compareTo(), which uses naive comparison of 64-bit values. This does NOT work as expected, given that underlying content is for all purposes unsigned. For example two UUIDs:
would be ordered with second one first, due to sign extension (second value is considered to be negative, and hence "smaller").
Because of this, you should always use external comparator, such as
com.fasterxml.uuid.UUIDComparator, which implements expected sorting order that is simple unsigned sorting, which is also same as lexicographic (alphabetic) sorting of UUIDs (when assuming uniform capitalization).
Available as part of the Tidelift Subscription.
The maintainers of
java-uuid-generatorand thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
For simple bug reports and fixes, and feature requests, please simply use projects Issue Tracker, with exception of security-related issues for which we recommend filing Tidelift security contact (NOTE: you do NOT have to be a subscriber to do this).
There are many other publicly available UUID generators. For example:
java.util.UUIDsince 1.4, but omits generation methods (esp. time/location based ones), has sub-standard performance for many operations and implements comparison in useless way
Note that although some packages claim to be faster than others, it is not clear whether:
so it is often best to choose based on stability of packages and API.