Can anybody explain what is difference between :
@Resource
UserTransaction objUserTransaction;
and
EntityManager.getTransac
UserTransaction refers to the JTA transaction entity. You will only be able to use this when there is a JTA module available in the application server: for example, if you're deploying an application with this on Tomcat (which by default does not support JTA), code relying on this will fail. This is default type of transaction used in EJB's and MDB's.
EntityManager.getTransaction() retrieves a local transaction entity. This also sometimes known as a resource local transaction.
Resource local transactions are very different from JTA transactions: among other things, resource local transactions are specific to a resource, whereas JTA transactions tend to be specific to a particular thread.
For more information on the difference between resource local and JTA transactions, see this stackoverflow answer here: What is the difference between a JTA and a local transaction?