Hi Vijay,
The first method is the right way to connect to CMS from a java application.
The exception you are getting states that there is a connectivity problem between the two machines.
You may want to check
1. Is there a firewall between you app server machine and BO server?
2. If yes, are you able to connect when firewall is turned off?(Consider windown firewall as well in case of windows system)
3. Do a network trace and the viable solution would be to configure the ports and open them for a two way communication over the firewall.
You could find the relavent information about configuring BO server ports over a firewall from admin guide which you can find at help.sap.com
Thanks,
Prithvi