Page 1 of 1

[HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Posted: Fri Jan 11, 2019 2:58 pm
by OCAJO1
page 76, "Working with Methods and Encapsulation" chapter . &

Chapter 8 makes much better reference variable to the address of "Working with Methods and Encapsulation" than Chapter . & :D

Page 76, 1. this is a keyword. That means you can't use it as variable name or class name.

I was wondering, shouldn't this sentence also include method name?

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Posted: Fri Jan 11, 2019 10:53 pm
by admin
OCAJO1 wrote:
Fri Jan 11, 2019 2:58 pm
page 76, "Working with Methods and Encapsulation" chapter . &
Chapter 8 makes much better reference variable to the address of "Working with Methods and Encapsulation" than Chapter.
Yes, it seems the chapter numbers were not decided when it was written. Even so, the sentence is ok, "...the "Working with Methods and Encapsulation" chapter.", implies the chapter with title "Working with Methods and Encapsulation" :)

Page 76, 1. this is a keyword. That means you can't use it as variable name or class name.

I was wondering, shouldn't this sentence also include method name?
and may be interface name, enum name, and package name also :D But yes, the sentence could be restructured to make it more clear.

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Posted: Tue Nov 19, 2019 5:22 pm
by Username987654
given
The compiler does not execute any code and it has no knowledge of the values that a variable might take during the execution of the program.
But when you do name = name;, the compiler cannot distinguish between the two name variables. It thinks that name refers to the method parameter and assigns the value of the method parameter to itself, which is basically redundant and is not what you want.
should be
But when you do name = name;, the compiler cannot distinguish between the two name variables. It thinks that name refers to the method parameter and the JVM (later) assigns the value of the method parameter to itself, which is basically redundant and is not what you want.
?

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Posted: Tue Nov 19, 2019 10:14 pm
by admin
No, this is fine. It is talking about what the compiler understands by name = name. The code name = name; implies that you are assigning the name to name. The actual assignment of the value is, of course, done by the JVM at runtime but the bytecode for that assignment is generated by the compiler.

In other words, " assigns the value of the method parameter to itself," means "the compiler generates the byte code that assigns the value of the method parameter to itself".

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Posted: Wed Nov 20, 2019 12:33 am
by Username987654
Thanks