]
Java,  Tutorial

Programming Zero Before Learning Java: Memory size

We will use something called variable, in programming language most of them uses variable to store different information.

I will write different analogies to help you understand variables feel free to jump to the next section if you feel you got my examples.

In school we used to have in mathematics equations like y = a + b. So it means y will equal the value of the sum between a and b. A could be anything and b could be any number. Still you are not strict to specific value to use, the point is the value of y is depending on what a and b represents.

To make it more simple let’s say you have a basket full of fruits and another one is full of fruits, if you wanna store them in the fridge, you can count each basket and you will be able to tell what will fridge will contain at any given time.

Data types

To explain all data types for a computer novice will be overkill for now. So we will introduce things slowly and later we will collect things in full post.

For now we will discuss int which represents a whole number like -1, 0, 2, 100303 ,-1390 and so on. Remember when we talked about memory blocks in the zero section, if you don’t please refer back to them to understand what I am saying, memory blocks have a size, the size can determine the maximum capacity that something can be stored in.

So every time you want to use a block after it reaches its maximum capacity you will need to get more space to store more stuff there.

Why I am saying all of that? Simply because every time you use a data type the processor will find you some blocks those blocks will have space enough to hold the value of the data type. But each data type was designed to ask for fixed amount of space unless you find a way to get more space than what current java standard library offers. Since

So for example when you hold int values you will be able to store amount of number the range could be -2,147,483,648 to 2,147,483,647.

Since we are grown now to know the range of int and memory blocks, now we can talk about the standard naming of our block. We call them bit, the bit is the smallest unit of storage and it records numbers between 0 or 1. But not the actual numbers we use but it’s like electric charge like on and off switch, we will not explain it more now but you can just know that when you see in the matrix movies those green numbers 0 and 1 they are referring to those bits.

Those bits are very small you can’t really store something in them to represent anything unless they are grouped together. Imagine having a paper and you just put a dot on the paper it won’t mean anything, you will need to draw or write more in a more physical space to create something understandable. The smallest amount of bits you need to make something meaningful in JAVA is 8 bits, and when you group them together you create one character or a range of numbers maximum is 255.

Storage units

In real life we have measurement units, to make life easier we convert certain units from its smallest form to an equivalent larger container. To simplify as we have 12 inches to one feet and 100 cm to meter. We have similar units with different naming in the digital world.

I’ll only go over the small units while you can look up conversions like kilo to megabytes and GB.

So we discussed that bits are the smallest unit. And the scientists in computer science probably decided that it’s the best way to name the second conversion byte and that would represent that 8 bit we discussed earlier. So every byte of data contains 8 bit.. so 2 bytes has 16 bits, 4 bytes will have 32 bits.

Leave a Reply

Your email address will not be published. Required fields are marked *