Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How java programs store in Heap and Stack.

 
rayan alex
Ranch Hand
Posts: 33
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I started java programming few weeks ago. Im trying to understand how java objects, variable and main program stored inside heap and stack.
I marked with question marks for places where i want to know. Please help me to understand.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Objects are stored on the heap*. The member variables of an object are stored in the object, on the heap. Local variables and argument variables are stored on the stack. Note that variables of non-primitive types in Java are not objects themselves, they are references to objects.

If you're new to Java, you might be focussing on the wrong thing. It's really not that important to know exactly where which variable is stored.

* Due to escape analysis, an advanced optimization, this is not strictly true. But you don't need to know that unless you're an expert on the internals of the JVM.
 
rayan alex
Ranch Hand
Posts: 33
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Welcome to the Ranch.

Objects are stored on the heap*. The member variables of an object are stored in the object, on the heap. Local variables and argument variables are stored on the stack. Note that variables of non-primitive types in Java are not objects themselves, they are references to objects.

If you're new to Java, you might be focussing on the wrong thing. It's really not that important to know exactly where which variable is stored.

* Due to escape analysis, an advanced optimization, this is not strictly true. But you don't need to know that unless you're an expert on the internals of the JVM.



Thank you for your reply. Currently im studding java in a Institute. I got some programs to resolve. But i have to explain in a way how java programs work with memory when running these programs.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rayan alex wrote: . . . But i have to explain in a way how java programs work with memory when running these programs.
Why? That ought not to be part of a beginner’s teaching.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic