《java入门第一季》之网络编程初探
2016-05-28 20:03
483 查看
由于在写有关javaweb的博客,在写到web服务器的时候需要回顾网络编程的知识,提前把网络编程放在前面写。
直接上代码解释:
输出结果:ydl-PC---192.168.1.105
直接上代码解释:
import java.net.InetAddress; import java.net.UnknownHostException; /* * 如果一个类没有构造方法: * A:成员全部是静态的(Math,Arrays,Collections) * B:单例设计模式(Runtime) * C:类中有静态方法返回该类的对象(InetAddress) * class Demo { * private Demo(){} * * public static Demo getXxx() { * return new Demo(); * } * } * * 看InetAddress的成员方法: * public static InetAddress getByName(String host):根据主机名或者IP地址的字符串表示得到IP地址对象 */ public class InetAddressDemo { public static void main(String[] args) throws UnknownHostException { // public static InetAddress getByName(String host) // InetAddress address = InetAddress.getByName("ydl-PC"); InetAddress address = InetAddress.getByName("192.168.1.105"); // 获取两个东西:主机名,IP地址 // public String getHostName() String name = address.getHostName(); // public String getHostAddress() String ip = address.getHostAddress(); System.out.println(name + "---" + ip); } }
输出结果:ydl-PC---192.168.1.105
相关文章推荐
- C#客户端发送http请求与服务器通信
- HTTPS的学习总结
- Linux下的TCP/IP编程----UDP实践篇
- linux虚拟机网络配置及Linux软件安装
- 网络编程(一)
- HTTP错误汇总
- http请求学习
- 安卓中HttpUrlConnection get和post请求方法
- TCP三次握手和四次挥手协议
- 浅谈HTTP中Get与Post的区别
- 航空路线问题[网络流24题之11]
- Charles抓取Android https包
- 卷积神经网络
- 防止短连接耗尽你的动态TCP端口
- android使用HTTP协议读取数据
- (美国云VPS)安装SQL2000图解教程 (一株网络)
- 网络 使用poll实现TCP服务器
- HTTP系列(四):Cookie
- Python中的plisttext和HTTP的Content-Type
- Linux下的TCP/IP编程----UDP篇