Update Icon with Unread messages number Notification

I want to update the icon for my App with a notification of how many unread alerts/messages user has for the app… Similar to what we see with Facebook or (Whatsapp icon showing how many unread messages are there).
Please point me to a sample code if possible.

Thanks.