diff --git a/build.gradle b/build.gradle index b4feb13d5..94d293993 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ subprojects { apply from: "$rootProject.projectDir/gradle/jmh.gradle" // apply from: "$rootProject.projectDir/gradle/checkstyle.gradle" apply from: "$rootProject.projectDir/gradle/findbugs.gradle" - apply plugin: 'com.mindviewinc.tagging' + //apply plugin: 'com.mindviewinc.tagging' } apply from: 'gradle/subprojects.gradle' diff --git a/objects/HelloDate.java b/objects/HelloDate.java index b408b1f48..a325d8f67 100644 --- a/objects/HelloDate.java +++ b/objects/HelloDate.java @@ -5,8 +5,14 @@ import java.util.*; public class HelloDate { - public static void main(String[] args) { - System.out.println("Hello, it's: "); - System.out.println(new Date()); - } +// public static void main(String[] args) { +// System.out.println("Hello, it's: "); +// System.out.println(new Date()); +// } + public static void main(String[] args) { + System.out.println("------"); + System.out.println(new Date()); + } } + + diff --git a/operators/Assignment.java b/operators/Assignment.java index c4b9a793e..c8212653a 100644 --- a/operators/Assignment.java +++ b/operators/Assignment.java @@ -16,7 +16,8 @@ public static void main(String[] args) { t2.level = 47; System.out.println("1: t1.level: " + t1.level + ", t2.level: " + t2.level); - t1 = t2; + // t1 = t2; 引用 + t1.level = t2.level; //实际对象 System.out.println("2: t1.level: " + t1.level + ", t2.level: " + t2.level); t1.level = 27; diff --git a/operators/Bool.java b/operators/Bool.java index 42668315b..8e216d876 100644 --- a/operators/Bool.java +++ b/operators/Bool.java @@ -26,6 +26,7 @@ public static void main(String[] args) { + ((i < 10) && (j < 10)) ); System.out.println("(i < 10) || (j < 10) is " + ((i < 10) || (j < 10)) ); + //如果在应该使用字符串的地方使用了布尔值,布尔值会自动转换成合适的文本格式 } } /* Output: diff --git a/operators/DoubleEquivalence.java b/operators/DoubleEquivalence.java index 5f06e25f5..0d3640990 100644 --- a/operators/DoubleEquivalence.java +++ b/operators/DoubleEquivalence.java @@ -1,49 +1 @@ -// operators/DoubleEquivalence.java -// (c)2021 MindView LLC: see Copyright.txt -// We make no guarantees that this code is fit for any purpose. -// Visit http://OnJava8.com for more book information. - -public class DoubleEquivalence { - static void show(String desc, Double n1, Double n2) { - System.out.println(desc + ":"); - System.out.printf( - "%e==%e %b %b%n", n1, n2, n1 == n2, n1.equals(n2)); - } - @SuppressWarnings("deprecation") - public static void test(double x1, double x2) { - // x1.equals(x2) // Won't compile - System.out.printf("%e==%e %b%n", x1, x2, x1 == x2); - Double d1 = x1; - Double d2 = x2; - show("Automatic", d1, d2); - Double r1 = new Double(x1); - Double r2 = new Double(x2); - show("new Double()", r1, r2); - Double v1 = Double.valueOf(x1); - Double v2 = Double.valueOf(x2); - show("Double.valueOf()", v1, v2); - } - public static void main(String[] args) { - test(0, Double.MIN_VALUE); - System.out.println("------------------------"); - test(Double.MAX_VALUE, - Double.MAX_VALUE - Double.MIN_VALUE * 1_000_000); - } -} -/* Output: -0.000000e+00==4.900000e-324 false -Automatic: -0.000000e+00==4.900000e-324 false false -new Double(): -0.000000e+00==4.900000e-324 false false -Double.valueOf(): -0.000000e+00==4.900000e-324 false false ------------------------- -1.797693e+308==1.797693e+308 true -Automatic: -1.797693e+308==1.797693e+308 false true -new Double(): -1.797693e+308==1.797693e+308 false true -Double.valueOf(): -1.797693e+308==1.797693e+308 false true -*/ +// operators/DoubleEquivalence.java // (c)2021 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. public class DoubleEquivalence { static void show(String desc, Double n1, Double n2) { System.out.println(desc + ":"); System.out.printf( "%e==%e %b %b%n", n1, n2, n1 == n2, n1.equals(n2)); } @SuppressWarnings("deprecation") public static void test(double x1, double x2) { // x1.equals(x2) // Won't compile System.out.printf("%e==%e %b%n", x1, x2, x1 == x2); Double d1 = x1; Double d2 = x2; show("Automatic", d1, d2); Double r1 = new Double(x1); Double r2 = new Double(x2); show("new Double()", r1, r2); Double v1 = Double.valueOf(x1); Double v2 = Double.valueOf(x2); show("Double.valueOf()", v1, v2); } public static void main(String[] args) { //比较0和最小的浮点数 test(0, Double.MIN_VALUE); System.out.println("------------------------"); //最大值 和 (最大值 和 (最小值只差的一百万倍))比较 一个非常大的数值减去一个相对较小的数值, //非常大的数值并不会发生显著变化。这个叫做 舍入误差 <\b> test(Double.MAX_VALUE, Double.MAX_VALUE - Double.MIN_VALUE * 1_000_000); System.out.println("------------------------"); test(2.1, 3.5); System.out.println("------------------------"); System.out.println(Double.MIN_VALUE); //2^-1074 System.out.println(Double.MAX_VALUE); } } /* Output: 0.000000e+00==4.900000e-324 false Automatic: 0.000000e+00==4.900000e-324 false false new Double(): 0.000000e+00==4.900000e-324 false false Double.valueOf(): 0.000000e+00==4.900000e-324 false false ------------------------ 1.797693e+308==1.797693e+308 true Automatic: 1.797693e+308==1.797693e+308 false true new Double(): 1.797693e+308==1.797693e+308 false true Double.valueOf(): 1.797693e+308==1.797693e+308 false true */ \ No newline at end of file diff --git a/operators/Overflow.java b/operators/Overflow.java index 68e494490..1a89a5561 100644 --- a/operators/Overflow.java +++ b/operators/Overflow.java @@ -8,7 +8,7 @@ public class Overflow { public static void main(String[] args) { int big = Integer.MAX_VALUE; System.out.println("big = " + big); - int bigger = big * 4; + int bigger = big * 4; // 数据不对 不是2147483647*4 System.out.println("bigger = " + bigger); } }