473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why are objects and variables stored where they are?

Hi

In Java Objects are stored in Heap and Primitive types and static varibables are stored in stack.
But my question is why Objects are stored in Heap and Primitive types and static varibables are stored in stack?

can any one know the answer please tell me.

Thanks
Vinoth
Mar 6 '08 #1
6 1562
JosAH
11,448 Expert 8TB
Hi

In Java Objects are stored in Heap and Primitive types and static varibables are stored in stack.
But my question is why Objects are stored in Heap and Primitive types and static varibables are stored in stack?

can any one know the answer please tell me.

Thanks
Vinoth
The only things that end up on the stack are local variables; either primitives or
references to objects. Object values are always stored somewhere in the heap.

kind regards,

Jos
Mar 6 '08 #2
BigDaddyLH
1,216 Expert 1GB
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Mar 6 '08 #3
The only things that end up on the stack are local variables; either primitives or
references to objects. Object values are always stored somewhere in the heap.

kind regards,

Jos

ok. Jos.
but i can't get the clear idea about this. let you know


thanks
vinoth
Mar 6 '08 #4
JosAH
11,448 Expert 8TB
ok. Jos.
but i can't get the clear idea about this. let you know


thanks
vinoth
What's still not clear then?

kind regards,

Jos
Mar 6 '08 #5
sukatoa
539 512MB
Hi

Originally Posted by vinothchandran
ok. Jos.
but i can't get the clear idea about this. let you know


thanks
vinoth
Here is the specific...

If you really know that the objects are in heap and primitive and static are in stack, you must accept that you got it from a book or in the internet... right?

If the book/that webpage tells you about that, then it should have the following explanation in the book/webpage why it tells you about that...

So, if until now, you are in doubt,

You can scan that book/webpage again and find that explanation... ;-)
If you are not satisfied with Jo's reply

Kind regards,
Sukatoa
Mar 6 '08 #6
satch
23
ok. Jos.
but i can't get the clear idea about this. let you know

thanks
vinoth
So I'm assuming that you are not clear about the difference between an object and a reference to an object, because that was the key thing to note in Jos's reply.
Read the discussion at the following link about difference between an object reference and object itself. Hope it helps you.

http://forum.java.sun.com/thread.jspa?threadID=652356&messageID=3836043
Mar 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
115
by: junky_fellow | last post by:
What is a C object ? If i have some function "func()" in my C program, then can i say that "func()" is a C object ? or if i have some function pointer (ptr) which contains the address of...
4
by: hufel | last post by:
Hi, I'm doing my first big project in C# and I'm stuck with a problem that I believe has a simple and efficient solution for it (I just haven't bumped into it yet...). The concept is the...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
2
by: Mel | last post by:
This may be a stupid question, but here goes... I have created a NameValueCollection in my website's application state. If, during a page request, I add a string key and string value to the...
7
by: MariusI | last post by:
Are objects implicitly stored in the TLS of the currently running thread? When creating multithreaded applications i get errors when accessing data from a different thread than the thread used to...
8
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.