adsense


Showing posts with label JAVA EXAMPLES HOST SPECIFIC IP ADDRESS. Show all posts
Showing posts with label JAVA EXAMPLES HOST SPECIFIC IP ADDRESS. Show all posts

Saturday, 31 October 2015

JAVA EXAMPLES HOST SPECIFIC IP ADDRESS PAGE 180

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES HOST SPECIFIC IP ADDRESS







Java Examples - Host Specific IP Address


Problem Description:
How to find hostname from IP Address?
Solution:
Following example shows how to change the host name to its specific IP address with the help of InetAddress.getByName() method of net.InetAddress class.
import java.net.InetAddress;

public class Main {
  public static void main(String[] argv) throws Exception {

    InetAddress addr = InetAddress.getByName("74.125.67.100");
    System.out.println("Host name is: "+addr.getHostName());
    System.out.println("Ip address is: "+ addr.getHostAddress());
  }
}
Result:
The above code sample will produce the following result.
http://www.javatutorial.com = 123.14.2.35


JAVA EXAMPLES HOST SPECIFIC IP ADDRESS PAGE 171

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES HOST SPECIFIC IP ADDRESS









Java Examples - Host Specific IP Address


Problem Description:
How to split a string into a number of substrings ?
Solution:
Following example shows how to change the host name to its specific IP address with the help of InetAddress.getByName() method of net.InetAddress class.
import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIP {
   public static void main(String[] args) {
      InetAddress address = null;
      try {
         address = InetAddress.getByName
         ("www.javatutorial.com");
      }
	  catch (UnknownHostException e) {
         System.exit(2);
      }
      System.out.println(address.getHostName() + "="
      + address.getHostAddress());
      System.exit(0);
   }
}
Result:
The above code sample will produce the following result.
http://www.javatutorial.com = 123.14.2.35