Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generating Windows GUID from Java  RSS feed

 
Manish Malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How does one generate a new Windows GUID from within Java?

I have been looking at the API available in .NET for this, and it involves a call to System.Guid.NewGuid() to get a new GUID generated. Does Java offer something similar for Windows environment?

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java offers no platform-specific APIs, period; so no, there's no built-in way to do this. There are, however, two options you can pursue: first, if there's a Windows executable that generates a GUID and prints it, you could run this program using Java's java.lang.Runtime.exec() method, and capture the output.

Another option is to use the JNI, the Java Native Interface, which lets you implement the body of a Java method using native (i.e., C/C++) code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!