So is the certificate now installed properly in the keystore (you can check with
keytool)? That
Java code you mentioned can do that, but "i have put it under security folder of JRE 6/7" sounds like you did something manually, and it doesn't sound like the right thing to do.
For development purposes something like
http://javaskeleton.blogspot.de/2010/07/avoiding-peer-not-authenticated-with.html would work. Don't ever use that across the public internet, though.