title: Check valid IPv4 Address in Java
body: <p>I am using the <code>sun.net.util.IPAddressUtil</code> package to check whether the string contains a valid IPv4 and IPv6 address or not.</p>
  
  <p>Code Snippet is:-</p>
  
  <pre><code>String ipv4addr="200";
  
      if(IPAddressUtil.isIPv4LiteralAddress(ipv4addr))
      {
          System.out.println("valid ipv4 address");
      }
      else
      {
          System.out.println("not valid");
  
      }
  </code></pre>
  
  <p>But for addresses such as 200 and 300 it is still saying it is a valid IPv4 address, which it isn't.
  When I used the same package and checked for IPV6 address using :-</p>
  
  <pre><code>String ipv6addr="200";
  
      if(IPAddressUtil.isIPv6LiteralAddress(ipv6addr))
      {
          System.out.println("valid ipv6 address");
      }
      else
      {
          System.out.println("not valid");
  
      }
  </code></pre>
  
  <p>I get the correct result. However, IPv4 does not seem to be working or may be I am using it incorrectly. Please guide me. I don't want to use regex for IPv4 validation...</p>