-4

I just want to know about the local variables are stored in stack memory

P Phyo
  • 9
  • The JVM is fundamentally a [virtual stack machine](https://en.wikipedia.org/wiki/Stack_machine#Virtual_stack_machines). – Elliott Frisch Jul 23 '19 at 04:15
  • Why not? Almost every other programming language does it too. Try reading up on the purpose of the [**Call Stack**](https://en.wikipedia.org/wiki/Call_stack). – Andreas Jul 23 '19 at 04:49

1 Answers1

0

The storage duration of local variables follow the LIFO(last in first out)principle.So using a stack -a LIFO data structure for allocating with LIFO storage is natural.Also the allocation and de-allocation of the memory is handled automatically unlike the heap.

Note that some local variables are stored in register also.This is since access to register is faster than access to the stack.

Animesh Jaiswal
  • 331
  • 3
  • 7