Skip to content

Commit

Permalink
update/add faq, add pic
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 13, 2023
1 parent db43d30 commit 81d2865
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
48 changes: 46 additions & 2 deletions doc/faq/faq_java.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
# JAVA FAQ
# Java FAQ

### 0) Ref

- https://javaguide.cn/java/basis/java-basic-questions-01.html
- https://cloud.tencent.com/developer/article/2183300


### Java basic data type VS reference data type **** ?
### Java basic data type (基本數據類型) VS reference data type (引用數據類型) **** ?

<img src ="https://github.com/yennanliu/CS_basics/blob/master/doc/pic/basic_ref_data_type.jpeg" width="500" height="300">

- 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 ?

Expand Down
7 changes: 7 additions & 0 deletions doc/faq/java_multi_thread.md
Original file line number Diff line number Diff line change
@@ -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 ?
Binary file added doc/pic/basic_ref_data_type.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions leetcode_java/src/main/java/dev/workSpace2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 (常量池))

}

Expand Down

0 comments on commit 81d2865

Please sign in to comment.