Take a look at this example: http://stilius.net/java/java_ssl.php
Don't try to invent your own cryptographic algorithm, I know that it sounds interesting but it's also not very safe. Try to use already implemented algorithms and protocols. I suggest you to take a look at the link. Though if you do this just for the fun of it then go ahead, if it's for a client or for something that others (than you at least) use then stick to the known protocols.