ufw has two ways to say no, and I think most people only ever type the first one. deny drops the packet without a word. reject sends an answer back, so the other side knows straight away that the door is shut.
The syntax is the same as for any other rule:
sudo ufw reject 8080/tcp
sudo ufw reject out smtp
sudo ufw status
The ufw source shows what happens underneath. A reject rule becomes an iptables REJECT target, and for TCP ufw adds --reject-with tcp-reset, following TCP’s normal behaviour of sending a reset. A client trying port 8080 gets an immediate “connection refused” instead of hanging until its timeout runs out. For UDP and other protocols iptables falls back to its default ICMP reply.
Where I’d use it: on my own LAN and for outgoing rules. The second line above blocks outgoing mail from the server itself, and a script that tries to send mail fails fast with a clear error instead of hanging for a minute. The manual also mentions reject for the case where you want the sender to know traffic is being denied. You can even make it the default with ufw default reject incoming.
The caveat: for ports facing the internet I’d stick with deny. A reject tells a scanner that a host is there and that it actively refused, and every refused probe costs you a reply packet. Silence gives away less. So deny on the public side, reject where the people knocking are your own scripts and machines.
Further reading: ufw manual page (Ubuntu), iptables-extensions: REJECT target