java代码

    public static void main(String[] args) {

        // int Integer区别
        Integer a = new Integer(3);
        Integer b = 3;
        int c = 3;
        System.out.println(a.equals(b));
        System.out.println(a == b);
        System.out.println(a == c);
        System.out.println(b == c);
        System.out.println("----------------------------------");

        // 自动装箱 拆箱 相关关系
        Integer f1 = 100, f2 = 100, f3 = 155, f4 = 155;
        /* 简单的说,如果整型字面量的值在-128到127之间,
         那么不会new新的Integer对象,
         而是直接引用常量池中的Integer对象,
         所以f1==f2的结果是true,而f3==f4的结果是false。*/
        System.out.println(f1 == f2); // true
        System.out.println(f3 == f4);  // false
        System.out.println("----------------------------------");

        // java虚拟机会自动调用System类
        // sun.misc.Version.init();
        // sun.misc.Version类会在JDK类库的初始化过程中被加载并初始化。
        String s1 = new StringBuilder("go").append("od").toString();
        System.out.println(s1.intern() == s1);
        String s2 = new StringBuilder("ja").append("va").toString();
        System.out.println(s2.intern() == s2);
        String s3 = new StringBuilder("Java(TM) SE ").append("Runtime Environment").toString();
        System.out.println(s3.intern() == s3);
        System.out.println("----------------------------------");

        // 四舍五入
        long round = Math.round(11.5);
        long round2 = Math.round(-11.5);
        System.out.println("round = " + round);
        System.out.println("round2 = " + round2);

        // i = 3 * 8(2的3次方)
        int i = 3 << 3;
        System.out.println("i = " + i);
        System.out.println("----------------------------------");

        // 数组没有length()方法,String有length()方法
        String length = "length";
        System.out.println(length.length());
        System.out.println("----------------------------------");

        // String StringBuilder StringBuffer 的区别
        String sr1 = "Programming";
        String sr2 = new String("Programming");
        String sr3 = "Program";
        String sr4 = "ming";
        String sr5 = "Program" + "ming";
        String sr6 = sr3 + sr4;
        System.out.println(sr1 == sr2);
        System.out.println(sr1 == sr5);
        System.out.println(sr1 == sr6);
        System.out.println(sr1 == sr6.intern());
        System.out.println(sr2 == sr2.intern());
        System.out.println("----------------------------------");

        // 交换x y 数值
        int x = 1;
        int y = 2;

        x = x ^ y; // 此时x的值为x ^ y用来暂存x和y的值
        y = x ^ y; // 即 y = (x ^ y) ^y = x ^ (y ^ y) = x ^ 0 = x; 此时y的值为1;
        x = x ^ y; // 即 x = (x ^ y) ^ x = y ^ (x ^ x) = y ^ 0 = y; 此时x的值为2;
        System.out.println("x = " + x);
        System.out.println("y = " + y);

        // 在数组中找出只出现一次的数字
        int[] nums = new int[5];
        nums[0] = 1;
        nums[1] = 1;
        nums[2] = 3;
        nums[3] = 2;
        nums[4] = 2;

        int iii = 0;
        for (int num : nums) {
            iii ^= num;
        }
        System.out.println("只出现一次的数字为" + iii);
        System.out.println("----------------------------------");

        // char类型可以存储一个中文汉字,
        // 因为Java中使用的编码是Unicode(不选择任何特定的编码,直接使用字符在字符集中的编号,这是统一的唯一方法),
        // 一个char类型占2个字节(16比特),所以放一个中文是没问题的。
        // char型变量中能存储一个中文汉字(这个汉字 𪚥(zhé 字符串为\uD869\uDEA5) 不行,那个biang打不出来所以试不成 )
//        char cr = '𪚥';
        char cr = '齉'; // nàng
        System.out.println("char类型包含一个汉字 = " + cr);

    }

运行结果

true
false
true
true
----------------------------------
true
false
----------------------------------
true
false
false
----------------------------------
round = 12
round2 = -11
i = 24
----------------------------------
6
----------------------------------
false
true
false
true
false
----------------------------------
x = 2
y = 1
只出现一次的数字为3
----------------------------------
char类型包含一个汉字 = 齉

Process finished with exit code 0

代码2

public class A {

    static {
        System.out.print("1");
    }

    public A() {
        System.out.print("2");


    }
}
public class B extends A{

    static {
        System.out.print("a");
    }

    public B() {
        System.out.print("b");


    }
}
public class AB {

    public static void main(String[] args) {

        A ab = new B();
        ab = new B();
    }


}

运行结果

1a2b2b

Never put off what you can do today until tomorrow