06 2020 档案
摘要:2.0、通过反射动态创建对象执行的方法 public class Test09 { public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationE
阅读全文
摘要:1.9、获取类的运行时结构 public class Test08 { public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException
阅读全文
摘要:1.8、分析类的初始化 public class Test06 { static { System.out.println("Main类被加载"); } public static void main(String[] args) throws ClassNotFoundException { //
阅读全文
摘要:1.7、类加载内存分析 public class Test05 { public static void main(String[] args) { A a = new A(); System.out.println(a.m); } } class A{ static { System.out.pr
阅读全文
摘要:1.6、所有类型的Class public class Test04 { public static void main(String[] args) { Class c1 = Object.class; //类 Class c2 = Comparable.class; //接口 Class c3
阅读全文
摘要:1.5、Class类的创建有哪些? public class Test03 { public static void main(String[] args) throws ClassNotFoundException { Person person = new Student(); System.o
阅读全文
摘要:1.4、反射 public class Test02 { public static void main(String[] args) throws ClassNotFoundException { //通过反射获取类的class对象 Class<?> c1 = Class.forName("com
阅读全文
摘要:1.3、自定义注解 public class Test03 { //对于没有默认值的注解必须显示赋值 // 有默认值的注解可以不再赋值 @MyAnnotation2(id = 11) public void test(){}; //注解只有一个参数时 多用value // 可以在配置的地方省略 va
阅读全文
摘要:注解和反射 1.1、 几个内置常用注解 //抑制警告,可以修饰在类和方法上 @SuppressWarnings("all") public class Test01 { //@Override 重写的注解 @Override public String toString() { return sup
阅读全文
摘要:创建线程及启动的几种方式 public class ThreadNew { public static void main(String[] args) { new MyThread1().start(); new Thread(new MyThread2()).start(); FutureTas
阅读全文
摘要:生产者消费者模式2-->信号灯法 public class TestPC2 { public static void main(String[] args) { TV tv = new TV(); new Player(tv).start(); new Watcher(tv).start(); }
阅读全文
摘要:生产者消费者模式-->管程法 public class TestPC { public static void main(String[] args) { SynContainer container = new SynContainer(); new Productor(container).st
阅读全文
摘要:Lock锁 public class TestLock { public static void main(String[] args) { Test t1 = new Test(); new Thread(t1).start(); new Thread(t1).start(); new Threa
阅读全文
摘要:死锁 public class DeadLock { public static void main(String[] args) { MakeUp g1 = new MakeUp(0, "小红"); MakeUp g2 = new MakeUp(1, "小绿"); g1.start(); g2.s
阅读全文
摘要:线程优先级 public class TestPriority { public static void main(String[] args) { System.out.println(Thread.currentThread().getName()+" >"+Thread.currentThre
阅读全文
摘要:观测线程状态 public class TestState { public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(()->{ for (int i = 0;
阅读全文
摘要:线程停止 public class TestStop implements Runnable { //1.设置一个标志位 private boolean flag = true; @Override public void run() { int i = 0; while (flag){ Syste
阅读全文
摘要:lambda表达式: //推导lambda表达式 public class TestLambda { //静态内部类 static class Like2 implements ILike{ @Override public void lambda() { System.out.println("I
阅读全文
摘要:浅谈静态代理模式: interface HappyMarry{ //接口对象 void marry(); } class You implements HappyMarry{ //真实角色 @Override public void marry() { System.out.println("小明要
阅读全文
摘要:多线程 一、创建多线程的几种方式 继承Thread类 实现runable接口 实现callable接口 *注意:*当创建一个线程后,调用的是start方法,会优先走主线程main;当调用的是run方法时,优先走run方法。线程的执行是CPU调度安排,故可能每次执行都不一样。 使用comments-i
阅读全文
摘要:文件上传 服务器端: public class TestServerDemo02 { public static void main(String[] args) throws Exception { //创建服务 ServerSocket serverSocket = new ServerSock
阅读全文