HIT 2020Spring Software Construction 0317

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.
Difference between two kinds of objects
To transfer a mutable class to a immutable class, we need to make the property to be final and private. And for those mutable property, the getter method should give a copy of the property instead of a reference. This is called defensive copying.
We should be aware the relationship between the reference and value.

It is only a post for what I want to record for the specific course and it does not stand for the whole content.

发布了10 篇原创文章 · 获赞 0 · 访问量 225

猜你喜欢

转载自blog.csdn.net/TroyHorse/article/details/104922333