Hi Debashis,
I think for your requirement UDF will be better than JAVA mapping.
You will get plenty of blogs for writing JAVA mapping. Try the upper mentioned solution.
Search some blogs for JAVA mapping. If you decide to go for JAVA mapping and stuck somewhere let me know I can help you then
Please don't forget to mark my answers helpful/Correct if it really helps you.
Thanks,
Apu