"It's me again. I forgot to explain something. I'll now tell you about variables and memory addressing. We won't delve too deeply, but it’ll be good if you remember at least something."
"I like your approach to lessons: If you understand something — great. If you don't understand anything — that's okay."
"Love can't be forced. That's obvious. Isn't that so on your planet?"
"No. We have a different approach. If you want to, you study; if you don't want to, you study, though unwillingly."
"What a backward approach to learning! That wastes a lot of energy and time and produces poor results."
"We waste it all right. But let's not talk about sad stuff."
"OK. Imagine Excel. Everybody knows Excel. An Excel sheet consists of cells. Each cell has its own unique identifier (A1, A2,…B1, B2). If you know a cell's identifier, you can always write some value into it or get whatever value is stored there. Computer memory is organized in a very similar way."
"I'm following you so far."
"The program and program data are stored in memory when the program is running. All computer memory is divided into small cells, or bytes. Each cell has a unique identifier, or number, associated with it: 0,1,2,3,… (the numbers start with 0). If you know a cell's number, you can save data in it. Or get data from it. Some cells store the program's code, i.e. the set of commands for the processor. Others store the data used by the program. Each cell's number is called its address."
"The Professor already told me about the processor and commands, but not in detail."
"The processor knows how to execute commands that have been loaded into memory. Almost all processor commands are something like 'take data from some cells, do something with them, send the result to other cells'. We combine hundreds of simple commands to get complex and useful commands."
"But why do I need all this?"
"When a variable is declared in code, a bit of memory that isn't already being used is assigned to it. This is usually a few bytes. Declaring a variable requires that you indicate the type of information the program will store in it: numbers, text or other data. For convenience, a unique name is assigned to each variable."
"Does that mean that a variable is a name, type, part of memory, and a value too?"
"It's all of those things rolled into one. Look at some examples:"
|This line creates a variable named
We can't declare another variable with the same name in the same function or class.
|This line creates a String variable named
|Here we create a variable named
|We create a variable named
"Here are some tasks for you, Diego. Work on them a little at a time."