How to check whether the device is connected to Internet?

How to check whether the device is connected to Internet?