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種原始數(shù)據(jù)類型
Primitive Data Type Wrapper的default value為
null
4.3 什么時候使用Primitive麦撵,什么時候使用wrapper上遥?
Primitive更efficient搏屑,當需要參與的計算非常的直接,不需要處理類型的轉(zhuǎn)換粉楚,不需要考慮極大辣恋,極小值等等時,優(yōu)先考慮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
好處: 在函數(shù)定義的時候指明返回值類型回俐,可以使對函數(shù)的使用更加明確逛腿。