Many programms(like chat-clients) use libnotify for telling the user that a new message has arrived. If a notification-daemon is running, a message will appear on the desktop. Most common desktop-environments have any notification-daemons preinstalled. Those services just print out messages for empty batteries or incomming chat-messages or so on.
A very lightweight notification-daemon for example is dunst.
It’s very easy to send notifications. Just install the libnotify-bin and use the command notify-send. Of course there are several API’s for different programming-languages.
Here is a very nice article about that topic.