CodeGym /Java Course /Java Syntax /Memory addressing and variables

Memory addressing and variables

Java Syntax
Level 1 , Lesson 3
Available

A lecture snippet with a mentor as part of the Codegym University course. Sign up for the full course.


"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."

Memory addressing and variables - 1

"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:"

Code Explanation
1
String s;
This line creates a variable named s. We declare its type as String, because it will be used to store text.
We can't declare another variable with the same name in the same function or class.
2
String s2 = "I'm Diego";
This line creates a String variable named s2 and immediately assigns the value "I'm Diego".
3
int a;
Here we create a variable named a. Its data type matches what will be stored in it. The int data type is short for integer.
3
int b = 4;
We create a variable named b. Its data type (int) is for storing integers. The value 4 is immediately assigned to the variable.

"Here are some tasks from Diego. Work on them a little at a time."

1
Task
New Java Syntax, level 1, lesson 3
Locked
It's cool to be a programmer!
Write a program that displays: "I think being a programmer is cool". Example output: I think being a programmer is cool
Comments (284)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
tpo5 Level 3, United States
15 November 2024
The amount of surprise and hate in the comments is absurd but also quite sad. More and more people these days expect to just be handed everything, the "participation trophy" generation. Quality education, or services and goods of any kind cost money. This program is one of the most if not the most affordable out there for what it covers. Do you think a team of programmers just decided to give up their time and money to build this hugely thorough course, pay for the domain, maintain the servers, build apps and plugins, all so the majority of people could hog bandwidth until the third lesson when they get bored or decide it's too hard or takes too long and gives up? I'm just baffled how anyone could expect something like this to be free. If you looked on the site home page you'd see on the left it clearly says subscriptions, implying payment is eventually required. Also if you scrolled down and read what the site offers, you'll see a pricing link on the bottom. It shouldn't bother me this much but it really does, the entitlement is what gets to me. There are free books, videos, websites, Java documentation, etc. that offer the same information as this site does, you can learn java that way if you're determined, that's how I started when i was broke and before I found this--even then I would have found $30 for a month for a course like this. $30/month is $1 a day. How are you even on the internet if you can't save $1 a day? If you're using a library computer I imagine your determination isn't an issue and you aren't here because you're busy learning Java the free (and harder) way. Complaining about paying for this site implies you're not really that determined but just like the way this course is set up, it's fun and easy to understand. Well, that's exactly why it costs money, and the codegym team deserves to be paid for creating such an intuitive java course. *old man rant over*
Jimmy Level 3, Lausanne, Switzerland
5 November 2024
stay hard, keep going
One Eyed Level 3, CodeGym University in India, India
1 September 2024
to this point i was really enjoying and was thinking its too good to be free. well sure as sh*t it aint free.. idk man i hate when this happens.
Anonymous #11519696 Level 2, Hong Kong, Hong Kong
5 June 2024
i cant pay please make me free premium, please.
Михаил Табакаев Level 2, -, Russia
15 May 2024
I cant pay plz make it free!!!
rags 3 Level 5, Wichita, United States Expert
23 April 2024
this is my second time first time got to level 7 then got busy 100 for a year aint bad this course does work and even makes you think different. stay with it and it'll happen for you
Anonymous #11498770 Level 2, Nigeria
5 April 2024
could they pls make if free!!!!!, not everyone wants to pay for a premium
Anonymous #11459401 Level 2, Rensselaer, United States
29 January 2024
i cant buy the premium
Anonymous #11459401 Level 2, Rensselaer, United States
29 January 2024
I cant do da task
Khrysus Level 3, Denver, United States
11 December 2023
Honestly with the sale and PayPal Pay-in-4, seems more than worth it for higher education in a very useful skill.
Anonymous #11498770 Level 2, Nigeria
5 April 2024
Seriously? 🙄😒