Types in Java
Primitives will be stored on stack and only values will be stored.
Object reference types will be stored on heap and their id will also be stored other than values.
Static Checking and Dynamic Checking
Static checking is done in the compile process and it will make sure values match the certain types.
While dynamic checking is processed in the run time. Dynamic checking tends to find a specific value valid or not in a particular situation.
Generally speaking, dynamic checking is more strict than static checking. Code without any kind of type checking will have lowest cost but have many annoying problems.
When it comes to java, it is a statically-typed language while Exception performs like dynamic checking.
Mutability and Immutability
It is a very important part in the exam and we may be asked to analyse a mutable class and transfer it to a immutable one.
要将可变类转换为不可变类,我们需要使该属性为final和private。 对于那些可变属性,getter方法应该提供该属性的副本,而不是引用。 这称为防御性复制。
我们应该意识到参考与价值之间的关系。