Hello Pankaj,
The simple answer to your question would be: These two are defined to use two different use cases altogether. UDF is used to cater much smaller subset/functionality inside a mapping as already explained above but Java Mapping is one of the mapping techniques in itself.
Just to add another point: Even beneath the graphical mapping essentially lies the java code. Even then, java mapping comes for help when standard functionality provided through graphical mapping is not enough or much complex.
Regards,
Ankit