diff --git a/doc/faq/faq_java.md b/doc/faq/faq_java.md index 60f4562e..491b7743 100644 --- a/doc/faq/faq_java.md +++ b/doc/faq/faq_java.md @@ -1,4 +1,4 @@ -# JAVA FAQ +# Java FAQ ### 0) Ref @@ -6,7 +6,51 @@ - https://cloud.tencent.com/developer/article/2183300 -### Java basic data type VS reference data type **** ? +### Java basic data type (基本數據類型) VS reference data type (引用數據類型) **** ? + + + +- basic data type : byte, short, int, long, float, dobule, char, boolean ... +- reference data type : Class, interface, Array + +- Note : + - basic data type : + - "==" : compare attr (value) + - equals : compare attr (value) + + - reference data type : + - "==" : compare storage address + - equals : + - NOT override : Still compare storage address (same as "==") + - override : compare attr (value) + - all class are child class of Object class + + ```java + // java + public boolean equals(Object obj) { + return (this == obj); + } + ``` + + ```java + // java + + // new Class : use a new storage in heap (內存) + String a = new String("123"); + String b = new String("123"); + + System.out.println(a==b); // false ( "new" will use new address in internal storage) + + // without new : will fetch from constant pool + String c = b; + + System.out.println(c==b); // true ( c will fetch from constant pool (常量池)) + ``` + +- https://blog.csdn.net/weixin_45658089/article/details/120248191 +- https://javaguide.cn/java/basis/java-basic-questions-02.html#object-%E7%B1%BB%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%E6%9C%89%E5%93%AA%E4%BA%9B + +### String、StringBuffer、StringBuilder ? ### Exception VS Error ? diff --git a/doc/faq/java_multi_thread.md b/doc/faq/java_multi_thread.md new file mode 100644 index 00000000..843a243f --- /dev/null +++ b/doc/faq/java_multi_thread.md @@ -0,0 +1,7 @@ +# Java Multi-thread FAQ + +- https://javaguide.cn/java/concurrent/java-concurrent-questions-01.html +- https://javaguide.cn/java/concurrent/java-concurrent-questions-02.html +- https://javaguide.cn/java/concurrent/java-concurrent-questions-03.html + +### Java multi thread ? \ No newline at end of file diff --git a/doc/pic/basic_ref_data_type.jpeg b/doc/pic/basic_ref_data_type.jpeg new file mode 100644 index 00000000..0ccf420e Binary files /dev/null and b/doc/pic/basic_ref_data_type.jpeg differ diff --git a/leetcode_java/src/main/java/dev/workSpace2.java b/leetcode_java/src/main/java/dev/workSpace2.java index 8373bd9b..f89c2ccd 100644 --- a/leetcode_java/src/main/java/dev/workSpace2.java +++ b/leetcode_java/src/main/java/dev/workSpace2.java @@ -12,12 +12,22 @@ public static void main(String[] args) { // // } - String x = "abcd"; - System.out.println(x.substring(1,3)); - StringBuilder sb = new StringBuilder(x.substring(1,3)); - System.out.println(sb.reverse()); +// String x = "abcd"; +// System.out.println(x.substring(1,3)); +// StringBuilder sb = new StringBuilder(x.substring(1,3)); +// System.out.println(sb.reverse()); +// +// System.out.println(x.substring(x.length()-1, x.length())); + + + String a = new String("123"); + String b = new String("123"); + + System.out.println(a==b); // false ( "new" will use new address in internal storage) + + String c = b; - System.out.println(x.substring(x.length()-1, x.length())); + System.out.println(c==b); // true ( c will fetch from constant pool (常量池)) }