1. Object & Variables
1.1 Object
Everything in Java is Object
1.2 Variables
是一個被name命名的storage location,里面存儲著一定的value。
可以具有不同的types
2. Control Structures
To modify the flow of code in a program
2.1 condition
- if
2.2 loop
- for
- while
- foreach
for(char c : charArray) {
...
}
3. Data Structures
To store data in an organized and efficient manner
3.1 Array
- fixed size
char[] charArray = new char[5];
3.2 ArrayList
- flexible size
List<Character> arrayList = new ArrayList<Character>();
3.3 Maps
- Key : Value
Map<String, List<String>> map = new HashMap<String, List<String>>();
4. Primitives & Wrapper
4.1 Primitives & its Object counterpart(Wrapper)
-
int
&Integer
-
boolean
&Boolean
-
double
&Double
-
float
&Float
-
char
&Character
4.2 Primitives Size & Default value
-
8種原始數據類型
Primitive Data Type Wrapper的default value為
null
4.3 什么時候使用Primitive,什么時候使用wrapper?
Primitive更efficient,當需要參與的計算非常的直接,不需要處理類型的轉換,不需要考慮極大,極小值等等時,優先考慮Primitive。 反之,考慮使用Wrapper。
5. Methods
code reuse
5.1 Access Control
a.k.a Access Modifiers
- Visible to the package, the default. No modifiers are needed.
- Visible to the class only (
private
). - Visible to the world (
public
).
because of class inheritance, all public methods and variables of a class are inherited by its subclasses. 所有public的東西會被子類繼承
- Visible to the package and all subclasses (
protected
).
同一個包,或者子類(無論同不同包)。因此可以理解為,隔離了非子類且不同包
5.2 Return Types
好處: 在函數定義的時候指明返回值類型,可以使對函數的使用更加明確。