Page 1 of 1

Re: [HD Pg 23, Sec. 1.9.0 - nomenclature]

Posted: Sun Nov 25, 2018 2:32 am
by Username987654
1.9.11
Similarly, literals such as the numbers 1, 2, and 3, or the characters written in code within single quotes such as ’a’, or boolean values true and false, are all compile time constants because the compiler knows that these values will never change.

(In my Review Copy) The text preceding this statement and 3.3 Declare and Initialize variables' examples appear to contradict the above (when not specified as final)? This does not currently appear to be found on the Errata page? Is the quote an error and/or possible opportunity for clarification?
will be removed tomorrow
Was the whole section removed in a later edit?

Re: [HD Pg 23, Sec. 1.9.0 - nomenclature]

Posted: Sun Nov 25, 2018 3:08 am
by admin
Username987654 wrote:
Sun Nov 25, 2018 2:32 am
1.9.11
Similarly, literals such as the numbers 1, 2, and 3, or the characters written in code within single quotes such as ’a’, or boolean values true and false, are all compile time constants because the compiler knows that these values will never change.

(In my Review Copy) The text preceding this statement and 3.3 Declare and Initialize variables' examples appear to contradict the above (when not specified as final)? This does not currently appear to be found on the Errata page? Is the quote an error and/or possible opportunity for clarification?
Do you mean this sentence on pg 24?
For example, if you define an int variable as final int x = 10; then x is a compile time constant because the compiler knows that x will
always have a value of 10 at run time
This statement is correct. Could you please specify which part/statement in 3.3 did you find contradictory to this statement?
will be removed tomorrow
Was the whole section removed in a later edit?
It was about the test post in this thread. Removed now.

thank you,
Paul.

Re: [HD Pg 23, Sec. 1.9.0 - nomenclature]

Posted: Sun Nov 25, 2018 10:48 am
by Username987654
Similarly (***when defined as final?***[would better? clarify this quote?]), literals such as the numbers 1, 2, and 3, or the characters written in code within single quotes such as ’a’, or boolean values true and false, are all compile time constants because the compiler knows that these values will never change.

Re: [HD Pg 23, Sec. 1.9.0 - nomenclature]

Posted: Sun Nov 25, 2018 11:34 am
by admin
Username987654 wrote:
Sun Nov 25, 2018 10:48 am
Similarly (***when defined as final?***[would better? clarify this quote?]), literals such as the numbers 1, 2, and 3, or the characters written in code within single quotes such as ’a’, or boolean values true and false, are all compile time constants because the compiler knows that these values will never change.
The similarity that is being referred to in those two things (i.e. final int x = 10 and literals 1, 2 etc.) is that both of them are compile time constants.

Normally, a variable can take any value (that is why it is called a "variable"). But, by applying the final modifier to x, we say that the variable x will always have the same value of 10.
1, 2, 3, 'a' etc, OTOH, are literals, they are not variables. They are values. So, the modifier "final" or any other modifier doesn't make sense for them.

That is why, saying "Similarly, when defined as final, literals such as the numbers 1, 2, and 3, ...", would be incorrect.

Section 3.3.3 Page 66 explains literals in more detail.

Re: [HD Pg 23, Sec. 1.9.0 - nomenclature]

Posted: Sun Nov 25, 2018 12:06 pm
by Username987654
Very well explained. Thanks!