it there any way to create a md5 for given string
First problem: you need to define which encoding you want to use to convert the string to bytes. MD5 works on binary data, not text. So you need to convert your string to bytes, then hash it, which will give you 16 bytes back as the hash.
that md5 should have only specified characters say only alphanumeric
Well, that's most easily done in hex, or base32 if you want to save a bit of space.
also the length of md5 should be coder defined using java
The size of the binary hashed data is fixed - MD5 always produces 128 bits (16 bytes). If you want to reduce the length, you'd potentially need to truncate the data (which makes the hash less effective). Of course, if your desired length is longer than it needs to be, you just need to pad it.
16 bytes would be encoded in hex as 32 characters, or in base32 as 26 characters. Base64 would only need 22 characters, but that requires at least two non-alphanumeric characters. (Digits + a-z + A-Z gives 62 characters; base64 needs 64 - usually plus a padding character, but that could be omitted if you know the length beforehand.)
If you could explain your requirements in more detail, we may be able to help more - but fundamentally MD5 is a fixed-size hash.