Hello Ganga,
There are no specific condition where you need to follow either java scripting or groovy in SAP HCI from my understanding ( I am not sure from Performance Perspective ).
You can go with Java Scripting if you are already good with java or if you are from PI background have in depth knowledge on XML Parser or you have repository of reusable codes from your SAP PI experience.
Where as Groovy scripting is considered you can learn very quickly if you are very new to scripting also because of developer friendly syntax and bunch of very strong built in classes for XML parsing.
For Ex:To parse a XML
In Groovy:
You can use XMLSlurper Class and can be done in few lines of code.
def root = new XmlSlurper().parseText(body)
def T_FILETYPE = root.header.FILETYPE
T_FILETYPE = T_FILETYPE.toString()
In JavaScript:
You need to write multiple lines of code using either SAX or DOM Parser ( you can check in SDN for examples on the same ).
Difference between them very nicely explained in the below blog
Practically Groovy: Building, parsing, and slurping XML
UDF:
UDF in SAP HCI is very similar to SAP PI,but here you will be creating a groovy script to achieve the same which can be used within the Message Mapping .
Script Step can be used within your Integration Process.If you are SAP PI background you can visualize something like you are writing Java Mapping.
Best starting point I would suggest is to go through the Standard Integration Packages available in SAP HCI Content Catalog ( https://cloudintegration.hana.ondemand.com/ ) where you can see multiple Scripts.
Regards,
Sriprasad Shivaram Bhat