title: Get domain name from given url
body: <p>Given a URL, I want to extract domain name(It should not include 'www' part). Url can contain http/https. Here is the java code that I wrote. Though It seems to work fine, is there any better approach or are there some edge cases, that could fail.</p>
  
  <pre><code>public static String getDomainName(String url) throws MalformedURLException{
      if(!url.startsWith("http") &amp;&amp; !url.startsWith("https")){
           url = "http://" + url;
      }        
      URL netUrl = new URL(url);
      String host = netUrl.getHost();
      if(host.startsWith("www")){
          host = host.substring("www".length()+1);
      }
      return host;
  }
  </code></pre>
  
  <p>Input: <a href="http://google.com/blah" rel="noreferrer">http://google.com/blah</a></p>
  
  <p>Output: google.com</p>