There's no matter what to use, exec() or system(). Use this sample and replace ClientName, OrganizationUnit etc. with your values
keytool -genkey -noprompt \
-alias alias1 \
-dname "CN=ClientName, OU=OrganizationUnit, O=Organization, L=Locality, S=State, C=CountryCode" \
-keystore keystore \
-storepass password \
-keypass password