InetAddress类的使用
来源:互联网 发布:超高温灭菌牛奶 知乎 编辑:程序博客网 时间:2024/05/18 02:40
InetAddress类的使用
没有构造方法,那么如何使类提供的功能呢?
没有构造方法的情况:
A:成员全部是静态的(Math,Arrays,Collection)
B : 单例设计模式(Runtime)
C:类中有静态方法返回该类的对象(InetAddress)
要掌握的功能:
获取任意主机:getByName
主机名:getHostName
主机Ip地址:getHostAddress
例子1:InetAddress类的使用
import java.net.InetAddress;
import java.net.UnknownHostException;
public classInetAddressDemo {
public static void main(String[] args)throws UnknownHostException {
// TODO Auto-generated method stub
//获取IP地址对象
// InetAddressaddress = InetAddress.getByName("wymA");
InetAddressaddress = InetAddress.getByName("219.216.80.19");
// 获取主机名
Stringname = address.getHostName();
// 获取IP地址
Stringip = address.getHostAddress();
System.out.println(name +"---" + ip);
}
}
运行结果:
219.216.80.20---219.216.80.20
- InetAddress类的使用
- InetAddress类的使用
- InetAddress类的使用
- InetAddress类的使用
- java InetAddress类、URL类的使用
- Java编程InetAddress类的使用
- java.net.InetAddress类的使用
- 使用InetAddress类获得域名的方法
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- java.net.InetAddress类的使用
- 1. java.net.InetAddress类的使用
- 网络编程InetAddress类的使用
- Socket & InetAddress的使用
- 网络编程模型及网络编程三要素
- 【SSH】Dispatcher initialization failed && Exception startingfilter struts2
- ORB-SLAM2编译遇到的一些问题
- 现在开始学程序还不晚吧
- ACM-2012 素数判定
- InetAddress类的使用
- 【CS231n Winter 2016 Lecture 1 (Brief history&course overview)】
- static和const的作用
- 为一个java项目生成文档by eclipse
- 6.关联容器
- 网络端口、协议、Socket
- 最少换乘 第八届
- 自定义控件入门
- android studio获取sha1值