Java备忘

Java 11 与 Java 8 的区别

日期

Java 11 多了 LocalDate.EPOCH 常量的定义, Java 8没有这个变量

public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);

Java中标签的使用

An unlabeled break statement terminates the innermost switchforwhile, or do-while statement, but a labeled break terminates an outer statement. 

Java中标签主要是用来中断或者跳转到指定循环(非中断/跳转语句直接所在的循环),以下是随手写的示例代码,仅为展示标签使用:

        int i = 0;
        OUT_1:
        do{
            for (; i < 100; i++) {
                OUT_2:
                for (int j = 5; j < 100; j++) {
                    for (int k = 10; k < 100; k++) {
                        int l = (int) (new Random().nextDouble() * (i + j + k));
                        if (l % 10 == 0) {
                            System.out.println("before break OUT_1");
                            break OUT_1;
                        }else if(l %10 == 2){
                            System.out.println("before break OUT_2");
                            break OUT_2;
                        }
                    }
                }
            }
        }while(true);
        System.out.println("the value of i is :: " + i);

如果随机生成的l值是10的倍数,则中断do-while循环;如果l值对10取模余数是2,则跳转到第二个for循环。

Maven 3.3.1+ requires JDK 1.7+.

Maven 3.3.1+ requires JDK 1.7+. Please set appropriate JDK at Settings | Build, Execution, Deployment | Build Tools | Maven | Runner | JRE

Leave a Reply

Your email address will not be published. Required fields are marked *