首页 > Web开发 > 详细

类InetAddress

时间:2017-01-27 11:46:59      阅读:446      评论:0      收藏:0      [点我收藏+]

 

如果一个类没有构造方法:
A:成员全部是静态的(Math,Arrays,Collections)
B:单例设计模式(Runtime)
C:类中有静态方法返回该类的对象(InetAddress)

public static InetAddress getByName(String host);//根据计算机名或者IP地址的字符串表示得到IP地址对象

 

import java.net.InetAddress;
import java.net.UnknownHostException;

/*
如果一个类没有构造方法:
A:成员全部是静态的(Math,Arrays,Collections)
B:单例设计模式(Runtime)
C:类中有静态方法返回该类的对象(InetAddress)

public static InetAddress getByName(String host);//根据计算机名或者IP地址的字符串表示得到IP地址对象
*/

public class Example6_3 {
	public static void main(String args[]) throws UnknownHostException {
		InetAddress address1 = InetAddress.getByName("QY-DENGGL18.gd.ctc.com");// 根据计算机名或者IP地址的字符串表示得到IP地址对象
		String name1 = address1.getHostName();// 获取计算机名
		String ip1 = address1.getHostAddress();// 获取IP地址
		System.out.println(name1 + "--------" + ip1);

		InetAddress address2 = InetAddress.getByName("10.18.46.40");// 根据计算机名或者IP地址的字符串表示得到IP地址对象
		String name2 = address2.getHostName();// 获取计算机名
		String ip2 = address2.getHostAddress();// 获取IP地址
		System.out.println(name2 + "--------" + ip2);
	}
}

 

类InetAddress

原文:http://www.cnblogs.com/denggelin/p/6353715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!