The final
Keyword
Variables can be marked final
, in which case
that variable cannot be re-assigned. Finality is a property
of variables; objects have no idea if a variable pointing at
them is final. So, a final variable can be used to tell an object
to change its state.
Constness Finality of variable + (primitiveness or immutibility of data) → constness.
Ideentifiers for constaants are all-caps.
The static
Keyword
A class is divided into to parts, instance land and static land. The static etiquette rule applies: Things in Instance Land have access to things in Static Land. However things in Static Land do not have direct access to things in Instane Land.
Notice the grease on the static side of the wall and the ladder-rungs on the instance side.
Instance land consists of things that can vary from one instance of the class to another. Static land consists of things that are the same for all instances of the class.
Instance Land -|G Static Land -|R -|E non-static (instance)-|A static methods methods -|S static data and -|E constants state variables -| and non-static -| constants -| ------------------------------------------------
when you make a class the class loader loads it into memory. A static area of memory is set aside for static items in the class All instances of the class can see it. Things that are static are accessed via the class name.
- access specifiers: public, private
- final (applies to variables)
- static (applies to variables or methods)