<body> <!-- 基本数据类型: 1)number 数值(整型,浮点都属于数值) 2)string 字符串(单引号,双引号),在JS中都是字符串,没有字符概念 3)boolean 布尔类型(true/false) 4)undefined 未定义 引用数据类型: let obj = new Object(); let date = new Date();
判断变量都数据类型: 语法:typeof变量名 --> <script>
//感知弱类型语言不注重变量的定义 let a; console.log(typeof a);
a = "ABC"; console.log(typeof a);
a = 'ABC'; console.log(typeof a);
a = 123; console.log(typeof a);
a = 123.123; console.log(typeof a);
a = true; console.log(typeof a);
a=new Object(); console.log(typeof a);
let stu = new Object(); stu.id = 1; stu.name = 'a'; stu.age = 18; console.log(stu); </script> </body>
@Override public ListIterator<String> listIterator() { thrownewUnsupportedOperationException("不允许调用listIterator方法"); }
@Override public ListIterator<String> listIterator(int index) { thrownewUnsupportedOperationException("不允许调用listIterator方法"); }
@Override public List<String> subList(int fromIndex, int toIndex) { return list.subList(fromIndex, toIndex); } @Override publicvoidsort(Comparator<? super String> c) { thrownewUnsupportedOperationException("不允许调用sort(Comparator<? super String>方法"); }
@Override public Spliterator<String> spliterator() { thrownewUnsupportedOperationException("不允许调用spliterator方法"); }}
} 1.6 Class对象中的三个常用方法 public String getName();//获取全限定类名 public String getSimple();//获取类名 public Object getInstance();//创建Class对象所代表的那个类的对象,底层实际上使用的是该类的无参构造
反射获取成员方法 public Method get Method(String name,Class…args);//获取public方法 public Method get getDeclaredMethod(String name,Class…args);//获取 任意修饰 方法 public Method[] get Methods();//获取所有的public成员,包括父类继承的 public Method[] get getDeclaredMethods();//获取所有任意修饰方法,不包含父类继承的
for (Method method : methods) { if (method.isAnnotationPresent(MyTest.class)) { method.invoke(newDemo()); }else { System.out.println("N Annotation"); } } }}
总结: 反射技术获取Class字节码对象 Class clazz = 类名.class; Class clazz = 对象名.getClass(); Class clazz = Class.forName(“包名”,”类名”);
通过反射技术怄气构造方法对象,并创建对象 获取构造: public Constructor getConstructor(参数的类型.class,…)//获取单个 public 构造 public Constructor getDeclareConstructor(参数的类型.class,…)//获取单个 任意修饰 构造 public Constructor[] getConstructors()//获取所有个 public 构造 public Constructor[] getDeclareConstructors()//获取所有 任意修饰 构造 使用构造: 构造方法对象.newInstance(实际参数); 如果是私有构造: 必须在使用之前设置暴力权限->构造方法对象.getAccessable(true);
反射获取成员方法对象,并调用方法 public Method getMethod(String name,参数的类型.class,…)//获取单个 public 方法 public Method getDeclareMethod(String name,参数的类型.class,…)//获取单个 任意修饰 方法 public Method[] getMethods()//获取所有个 public 方法,包括父类继承的 public Method[] getDeclareMethods()//获取所有 任意修饰 方法,不包含父类的
System.out.println("程序继续执行.."); while (true) { Thread.sleep(1000); }
} }
总结: Selector作用: Selector可以让多个服务器注册到它上,完成多路复用功能
使用Selector选择器 注册: channel.register(selector,SelectionKey.OP_ACCEPT); 方法: //表示所有被连接到服务器通道的集合 public Set selectedKeys(); Set keys = selector.selectedKeys();
//获取所有已经成功注册到选择器的服务器通道集合 public Set keys(); Set keys = selector.keys();
//如果目前没有客户端连接,该方法会阻塞。如果有客户端连接会返回本次连接的客户端数量 public int select(); int count = selector.select();
3.byteBuffer的三种添加数据方式 public ByteBuffer put(byte b);//添加单个字节 public ByteBuffer put(byte b,bs);//添加字节数组 public ByteBuffer put(byte b,bs,int startIndex,int len);//添加一个字节数组中的一部分
8.byteBuffer的其他方法 public int remaining();//获取position与limit之间的元素数 public boolean isReadyOnly();//获取当前缓冲区是否可读 public boolean isDirect();//获取当前缓冲区是否为直接缓冲区 public boolean clear();//还原缓冲区的初始状态
将position设置0 将limit置为capacity 丢弃标记 public Buffer flip();//切换读写模式(缩小范围)
将limit设置为当前position位置 将当前position位置设置为0 丢弃标记 public Buffer rewind();//重绕缓冲区
创建和使用ByteBuffer 创建: public static allocate(int capacity);//在堆区中申请一个固定大小的ByteBuffer缓冲区 public static allocateDirect(int capacity);//在系统的内存中申请一个固定大小字节的ByteBuffer缓冲区 public static wrap(byte[] arr);//把一个字节数组直接包装成ByteBuffer缓冲区 使用: public ByteBuffer put(byte b);//添加单个字节 public ByteBuffer put(byte b,bs);//添加字节数组 public ByteBuffer put(byte b,bs,int startIndex,int len);//添加一个字节数组中的一部分 public int capacity();//获取Buffer容量 buffer.limit(); buffer.position(); buffer.mark(); public int remaining();//获取position与limit之间的元素数 public boolean isReadyOnly();//获取当前缓冲区是否可读 public boolean isDirect();//获取当前缓冲区是否为直接缓冲区 public boolean clear();//还原缓冲区的初始状态 public Buffer flip();//切换读写模式(缩小范围) public Buffer rewind();//重绕缓冲区