zoukankan      html  css  js  c++  java
  • 类InetAddress

    如果一个类没有构造方法:
    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);
    	}
    }
    
  • 相关阅读:
    e552. 取Applet的参数
    e551. 精简的Applet
    e558. 在Applet中多图片交互显示
    e1087. try/catch语句
    e1086. if/else语句
    e1087. 用For循环做数组的遍历
    e1084. 捕获错误和异常
    Zookeeper 应用程序
    Zookeeper API
    Java并发编程:volatile关键字解析
  • 原文地址:https://www.cnblogs.com/denggelin/p/6353715.html
Copyright © 2011-2022 走看看