File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How java programs store in Heap and Stack. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How java programs store in Heap and Stack. " Watch "How java programs store in Heap and Stack. " New topic
Author

How java programs store in Heap and Stack.

rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
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

Joined: Aug 16, 2005
Posts: 14338
    
  22

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
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

Joined: Oct 13, 2005
Posts: 39784
    
  28
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
 
subject: How java programs store in Heap and Stack.