Is there way for port forwarding to AWS MongoDB cluster

Can anybody please provide guidance on how to write java code for port forwarding for command below?

ssh -N -i xxxxxxxx-us-east-1.pem -L

I want to connect with mongodb but before that I need to do port forwarding. Whenever I have to connect with mongodb. I have to run the command in command line, then I can connect with db via java code.

I want to do port forwarding via code as well. Thanks.