You can pipe your output to awk to print just the PID. For example:
ps -ef | grep nginx | awk '{print $2}'9439
You can use:
ps -ef | grep '[j]ava'
Or if pgrep is available then better to use:
pgrep
pgrep -f java
Use this: ps -C <name> -o pid=
ps -C <name> -o pid=