What will happen in memory, when we run a java program?
Memory architecture of a java program:
Once you compile and execute your java program, it will be loaded into memory (RAM).
Note: Remember if you want to run a program, it should be loaded into RAM.
Once it is loaded into memory, it will become a process.
Every process in memory will be allocated many segments. Out of which 4 segments are very important.
So every java program, once executed, it will have 4 segments in memory.
1.Data segment (stores static variables)
2.Code segment (stores your code)
3.Stack (stores local variables)
4.Heap (stores objects, and instance variables)
Below diagram shows the pictorial representation of a java program's memory architecture.
As long as your program is in hard disk it is called as program or application.
Once it is loaded into memory, it is called as a process.