Feb 13

Memory and Objects in Java

On a very early time of a day, (not quite early actually, it is 8:30, however monday+tuesday syndromes are in effect.) a very interesting topic was introduced. “Memory and Objects in Java”!

With that, whole class were awakened without noticing anything but only the topic…(LOTR!*)

Never mind, as you know from my previous blog post (a month ago?) in the first semester, I have taken the CS101 class. (Introduction to Computer Science) But this semester, things Screenshot_2_26_13_11_50_PM-3are starting to get much exciting than before.

We started to learn some advanced stuff about OOP etc. This week is a special one!

Java stores programmer-created objects in a very interesting way. JVM(Java Virtual Machine) divides memory to three different sections. (as it can be seen in the figure 1)

Static data section is simply the things that are defined as “public static …”. This part does not shrink or expand after the program is executed.

Heap section is the part that the objects that are initialized and stored in the memory and can shrink and expand later on.

Stack section is the same for shrinking and expanding, however stack section only stores the pointers(references). With using these references you can find your objects that are stored in the heap. You can make signals too!*

Hacking:(Small anecdote from our instructor(Dr. Murat Sensoy) In old days, the mighty/evil hackers override these rules and expand/shrink these sections to change the behavior of the program. It is now clear that why modern games use anti-cheating software(like Punkbuster, VAC) that scans memory, which is allocated by the games, in order to prevent such kind of hacking.

For more detailed information and cool animations that shows how it actually works, I recommend you to download this presentation file.

*: Check the presentation files