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种原始数据类型
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
好处: 在函数定义的时候指明返回值类型,可以使对函数的使用更加明确。