为啥有这个红色下划线?错误吗?运行正常啊
端口号最多6.5w个,如果一个一个电脑上的应用程序太多,怎么办呀。是相同的应用程序比如qq,在不同的电脑上,端口号不同。还是只要是qq,在所有电脑上端口号都一样。
/** * 按年龄排序的比较器 */ class OrderByAge implements Comparator<Person>{ @Override public int compare(Person o1, Person o2) { // //判断o1获取的age 大于o2获取的age,返回1(按照年龄的由小到大排序) if (o1.getAge() > o2.getAge()) { return 1; } return -1; } }
Person类中age定义的int类型,怎么使用CompareTo方法呢????
这里我使用的if判断
资料描述有问题吧,修改一下吧,会误导别人,
老师,就是服务端和客户端创建好后运行,就运行不出来,后来检查了一下发现是创建客户端时pw.println写成那个pw.print了,当时感觉print和println差不多,只是换行不换行的问题,没有改就运行不出来。
改了之后就运行出来了,这是为什么?
老师,第31行的valueOf有什么用,后面括号里要求输入的已经是int型了啊但是valueOf删了运行不了
引用ArrayList那里不是很懂,比如我是ArrayList list = new ArrayList();当我想换linklist容器时直接把这一句话改成LinkList list = new LinkList();不就好了,不麻烦呀,后面需要改什么?
重写toString方法里 用new StringBuffer实例化对象,而不去使用String去实例化方法的原因是由于String是固定的不可改变的字符串类型没有add方法,而StringBuffer可以进行修改,有相应的add方法,是这样吗,还是由于别的原因
老师为什么那个头结点head不能移动而是重新定义一个节点然后把头结点给他(node)让他进行移动呢
老师,s读取的是字节流,为什么不直接创建BufferedInputStream缓冲区?
启动服务器后打开网页输入URL之后,eclipse里面没有显示信息,可能是什么原因?
/** * 创建发送消息类 */ class ClientSend extends Thread { private Socket socket; public ClientSend(Socket socket){ this.socket = socket; } @Override public void run() { this.sendMsg(); } /** * 发送消息 */ private void sendMsg(){ Scanner scanner = null; PrintWriter pw = null; try { //键盘输入 scanner = new Scanner(System.in); //创建向对方输出消息的流对象 pw = new PrintWriter(this.socket.getOutputStream()); while (true){ String msg = scanner.nextLine(); if ("exit".equals(msg)){ break; } pw.println(msg); pw.flush(); } } catch (IOException e) { e.printStackTrace(); }finally { if (pw != null){ pw.close(); } if (scanner != null){ scanner.close(); } if(this.socket!=null){ try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } } /** * 创建接收消息线程类 */ class ClientReceive extends Thread { private Socket socket; public ClientReceive(Socket socket){ this.socket = socket; } @Override public void run() { } /** * 接收消息的方法 */ private void receiveMsg(){ BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); while (true){ String msg = br.readLine(); System.out.println("他说: " +msg ); } } catch (IOException e) { e.printStackTrace(); }finally { if (br!=null){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } } public class PointSocketClient { public static void main(String[] args) { try { Socket socket = new Socket("127.0.0.1",8888); System.out.println("连接成功"); new ClientSend(socket).start(); new ClientReceive(socket).start(); } catch (IOException e) { e.printStackTrace(); } } }
/** * 创建发送消息类 */ class Send extends Thread{ private Socket socket; public Send(Socket socket){ this.socket = socket; } @Override public void run() { this.sendMsg(); } /** * 发送消息 */ private void sendMsg(){ Scanner scanner = null; PrintWriter pw = null; try { //键盘输入 scanner = new Scanner(System.in); //创建向对方输出消息的流对象 pw = new PrintWriter(this.socket.getOutputStream()); while (true){ String msg = scanner.nextLine(); if ("exit".equals(msg)){ break; } pw.println(msg); pw.flush(); } } catch (IOException e) { e.printStackTrace(); }finally { if (pw != null){ pw.close(); } if (scanner != null){ scanner.close(); } if(this.socket!=null){ try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } } /** * 创建接收消息线程类 */ class Receive extends Thread{ private Socket socket; public Receive(Socket socket){ this.socket = socket; } @Override public void run() { this.receiveMsg(); } /** * 接收消息的方法 */ private void receiveMsg(){ BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); while (true){ String msg = br.readLine(); System.out.println("他说: " +msg ); } } catch (IOException e) { e.printStackTrace(); }finally { if (br!=null){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } } public class PointSocketServer { public static void main(String[] args) { ServerSocket serverSocket = null; try { serverSocket =new ServerSocket(8888); System.out.println("服务器启动等待连接....."); Socket socket = serverSocket.accept(); System.out.println("连接成功"); new Send(socket).start(); new Receive(socket).start(); } catch (Exception e) { e.printStackTrace(); }finally { if (serverSocket != null){ try { serverSocket.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
老师我这个代码只有客户端给服务端发消息的收回会输出
服务端给客户端发消息时没有反应,麻烦老师看下
有时候需要导包有很多选择,请问怎么选择应该导哪个包呢
怎么能让任务调度自动关闭呢?????????????????
请问老师,学生这样理解做的对不对
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637