zoukankan      html  css  js  c++  java
  • Java的一些细节语法(不定时更新。。。)

    目录

      1. ConcurrentHashMap不允许key为null,但是HashMap是可以的。TreeMap key不支持null。

      2. 以下代码里面,请注意:

        Integer a = 150;
        Integer b = 150;
        Integer c = 100;
        Integer d = 100;
        Integer e = new Integer(100);
        System.out.println(a == b); //false
        System.out.println(a == 150); //true  这种是真正的在对比值的大小
        System.out.println(c == d); //true
        System.out.println(c == e); //false
        
      3. Process类有输出流,输入流,错误流。

      4. 关于nio里面Bufferduplicate方法:

        ByteBuffer buf = ByteBuffer.allocate(100);
        /**
                 * duplicate函数的官方注释,并不是真正的复制。
                 * Creates a new byte buffer that shares this buffer's content.
                 *
                 * <p> The content of the new buffer will be that of this buffer.  Changes
                 * to this buffer's content will be visible in the new buffer, and vice
                 * versa; the two buffers' position, limit, and mark values will be
                 * independent.
                 * */
        ByteBuffer buf2 = buf.duplicate();
        
      5. Java Stream的数据源有容器,数组和I/O,Stream的中间操作(intermediate function)并不会直接执行,只有遇到终端操作(terminal function)才会开始执行。

      6. 在Java里面, count = count++,会导致count++没有效果,这个从字节码层面是可以解释的。

                 0: iconst_0
                 1: istore_1    // 将0存入到参数1的位置
                 2: iload_1     //将参数1的位置,也就是0,读取到操作数栈
                 3: iinc          1, 1   //给参数1的位置的参数直接+1
                 6: istore_1            //将操作数栈顶,也就是0,存储在参数1的位置
                 7: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
                10: iload_1  //将参数1的位置,也就是0,读取到操作数栈
                11: invokevirtual #3                  // Method java/io/PrintStream.println:(I)V
                14: return
        

        相对的,count = ++count的字节码如下:

                 0: iconst_0
                 1: istore_1    // 将0存入到参数1的位置
                 2: iinc          1, 1   // 将参数1的位置,也就是0,直接+1,
                 5: iload_1     // 读取参数1的位置,也就是1,放在操作数栈
                 6: istore_1    // 将操作数栈顶的值,也就是1,存储在参数1的位置
                 7: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
                10: iload_1     // 将参数1的位置,也就是1,读取到操作数1栈
                11: invokevirtual #3                  // Method java/io/PrintStream.println:(I)V
                14: return
        
        

        注意观察两段代码iinc前后的区别。

      7. Java的栈帧包括:局部变量表,操作数,动态链接,方法返回地址(注意,不包含本地方法栈)

      8. 通过DataSource对象访问的驱动程序本身不会向DriverManager注册,且其对象属性是可以进行更改的,如果服务器配置发生了变化,可以通过更新DataSource来进行对应的适配。

    • 相关阅读:
      Redis分布式缓存系列(六)- Redis中的List类型
      Redis分布式缓存系列(五)- Redis中的ZSet类型
      Redis分布式缓存系列(四)- Redis中的Set类型
      Redis分布式缓存系列(三)- Redis中的Hash类型
      Redis分布式缓存系列(二)- Redis中的String类型以及使用Redis解决订单秒杀超卖问题
      Redis分布式缓存系列(一)- Redis客户端及服务端的安装
      .NET中常用的数据结构
      面向对象23种设计模式系列(四)- 迭代器模式
      .NET中的本地缓存(数据分拆+lock锁)
      .NET中的GC垃圾回收
    • 原文地址:https://www.cnblogs.com/seancheer/p/13427584.html
    Copyright © 2011-2022 走看看