There are off-the-shelf libraries available. (A quick Google search turned up a product called JLicense, for example.) But it's not difficult and also more flexible to implement your own mechanism. One simple approach would be to compute the SHA-1 hash of the customer name plus some hard-coded salt. Encode the result as alphanumeric characters and you've got yourself a license key. Now, when someone goes to install your product, ask for their customer name and the license key. Recompute the hash and compare it to the customer key the user gave you to authenticate the key.
That's just one simple example. There's all kinds of things you can do including encrypting some data and storing it in the key (e.g. an expiration date or subset of unlocked features). You can make it as simple or complicated as you like.
Bear in mind, though, that any solution you come up with can be reverse-engineered by someone with enough skill and motivation, unless you use some kind of distributed authentication system. This is arguably easier to achieve in Java than with native compiled languages like C or C++. Obfuscating the code can help.