Find All broken Links in a Web Page

Code to find all broken links in a web page. Broken links are the links which navigates no where, i.e. they return http status code other than 200. For example if page is not fond than status code will be returned as 404.

More on HTTP status code here:

In below code we are trying to get all the urls from the page first and then using java classes (URL and HttpUrlConnection) to hit the urls.