Many a times you would get a "Bind Exception", "Address already in use" kind of errors and need to find the process that's using the port. For example say the port is 8080. The following command will get you the pid and program name as well.
netstat -nlept | grep "8080"
The result might look something like this...
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp6 0 0 :::8080 :::* LISTEN 1000 994652 4024/java
Where 4024 is the pid and it's a java app.