public class MyInteger { private static int value; private static MyInteger[] cache; private static final int HIGH=127; private static final int LOW=-128; static { cache=new MyInteger[HIGH-LOW+1]; for(int i=LOW;i<=HIGH;i++){ cache[i+128]=new MyInteger(i); } System.out.println(Arrays.toString(cache)); } @Override public String toString() { return value+""; } public MyInteger(int value){ this.value=value; } public static MyInteger ValueOf(int value){ return new MyInteger(value); } public int intValue(){return value;} public static void main(String[] args) { MyInteger a=new MyInteger(100); MyInteger b=a.ValueOf(100); System.out.println(a+"\n"+b); int c=a.intValue(); System.out.println(c); } }
老师,请问我这个结果为什么都是一样的,哪里出问题了吗?
老师这里不加双引号输出结果为啥还是数字啊?
老师,为什么这里就不把Socket创建在Try外面了呢
老师,直接在A的run方法里创建B的线程对象实现包装,在A类中联合,和课堂讲的区别在哪里呢
class A implements Runnable{ @Override public void run() { Thread t3 =new Thread(new B()); t3.start(); for(int i=0;i<10;i++){ if(i==5){ try { t3.join(); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println(Thread.currentThread().getName()+": A"+i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } class B implements Runnable{ @Override public void run() { for(int i=0;i<20;i++){ System.out.println(Thread.currentThread().getName()+" B"+i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } public class TestJoinThread { public static void main(String[] args) { Thread t1 = new Thread(new A()); t1.start(); for(int i=0;i<10;i++){ System.out.println(Thread.currentThread().getName()+" "+i); //当主线程迭代因子为2时,并入A线程 if(i==2){ try { t1.join(); } catch (InterruptedException e) { e.printStackTrace(); } } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
ByteArrayInputStream是节点流吗
老师,URL和TCP一般都是URL用的多是吗?
package com.Thread; /** *测试缓冲区的作用 */ public class TestBufferThread { public static void main(String[] args) { SyncStack ss=new SyncStack(); new XiaoFei(ss).start(); new Product(ss).start(); } } /*** * 设置一个馒头类 */ class Mantou{ private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } /*** * 设置缓冲区 */ class SyncStack{ //定义存放那个馒头的盒子 private Mantou[] mt=new Mantou[10]; //操作馒头的索引 private int index; /** * 放馒头 */ public synchronized void push(Mantou mantou){ //判断盒子是否满 while (this.index==this.mt.length){ try { /** * 语法:wait(),该方法必须要在synchronized块中调用。 * wait执行后,线程会将持有的对象锁释放,并进入阻塞状态, * 其他需要该对象锁的线程就可以继续运行了。 */ this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } //唤醒取馒头的线程 /** * 语法:该方法必须要在synchronized块中调用。 * 该方法会唤醒处于等待状态队列中的一个线程。 */ this.notify(); this.mt[this.index]=mantou; this.index++; } } /** * 取馒头 */ public synchronized Mantou pop(){ while(this.index == 0){ try { /** * 语法:wait(),该方法必须要在synchronized块中调用。 * wait执行后,线程会将持有的对象锁释放,并进入阻塞状态, * 其他需要该对象锁的线程就可以继续运行了。 */ this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } this.notify(); this.index--; return this.mt[this.index]; } } /** * 定义生产者线程 */ class Product extends Thread{ //传入缓冲区 private SyncStack ss; public Product(SyncStack ss){ this.ss=ss; } @Override public void run() { for (int i = 0; i <10 ; i++) { Mantou mt=new Mantou(); mt.setId(i); System.out.println("生产馒头"+mt.getId()); this.ss.push(mt); } } } /** * 定义消费者线程 */ class XiaoFei extends Thread{ private SyncStack ss; public XiaoFei(SyncStack ss){ this.ss = ss; } @Override public void run() { for(int i=0;i<10;i++){ Mantou mt = this.ss.pop(); System.out.println("消费馒头:"+mt.getId()); } } }
老师,帮我看看,只启动生产者线程,消费者线程没反应?
老师后来这里接口引用类型是什么意思
老师1您好,可否再进一步解释一下视频中提到的bean。
谢谢!
老师第九行这种是什么赋值方式呢
import com.Jin.FuWuQi.KeHuDuan.IOClose; import java.io.*; import java.net.ServerSocket; import java.net.Socket; public class Server2 { public static void main(String[] args) { String CRLF = "\r\n";//换行 String BLANK = " ";//空格 ServerSocket server = null; Socket client = null; InputStream is = null; try { //(1)创建ServerSocket对象 server = new ServerSocket(8888); //(2)监听是否有客户端发送请求 client = server.accept(); //获取来自浏览器的请求信息 is = client.getInputStream(); byte []buf = new byte[20480]; int len = is.read(buf); System.out.println(new String(buf,0,len)); /** * 对wed浏览器的请求作出响应 */ StringBuilder sb = new StringBuilder(); StringBuilder sbContent = new StringBuilder();//请求文本 sbContent.append("<html><head><title>响应结果</title></head>"); sbContent.append("<body>登陆成功</body></html>"); //1.拼接响应头 sb.append("HTTP/1.1").append(BLANK).append(200).append(BLANK).append("OK"); sb.append(CRLF); sb.append("Content-Type: text/html;charset=uft-8"); sb.append(CRLF); sb.append("Content-Length:").append(sbContent.toString().getBytes().length).append(CRLF); sb.append(CRLF);//换行,代表响应头与响应正文部门之间的空行 sb.append(sbContent); //通过流输出 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(client.getOutputStream(),"utf-8")); bw.write(sb.toString()); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); }finally { //(6)关闭流 IOClose.closeAll(is,client,server); } } }
运行都正常,登陆也没问题
就是一进去就乱码
改编码格式,改成UTF-8,也是显示乱码,到底是哪里出了问题呢
if(this.size == 0){ throw new EmptyStackException(); }
判断数组元素是否为空,能否直接用size判断
老师 ArrayList不是要重写接口中的方法嘛 重写接口中的方法之后ArrraList为什么还会拥有接口中的方法啊
老师,我想问一下,最后的服务器类中的关闭流那里,是因为加了while(true)使得代码一直处于循环状态,所以就不需要关闭流了是吗?
老师,为什么在内部类中,next 、head 还有tail的类型要定义成Node类?不能定义成泛型嘛或者其他类型?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637