Re: how java variables are stored?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Mon, 15 Aug 2005 20:55:51 GMT
"Thomas G. Marshall" <tgm2tothe10thpower@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message news:zk4Me.1157$zb.479@xxxxxxxxxxx
> Roedy Green coughed up:
>> On Mon, 15 Aug 2005 00:34:17 GMT, "Thomas G. Marshall"
>> <tgm2tothe10thpower@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote or quoted
>>>
>>
>>> This does not answer the OP's question. His question was
>>> specifically (para-phr): Why does the variable need space in *both*
>>> the stack and the heap, and what it means.
>>
>> to answer that question he has to understand the difference between a
>> reference and an object. The reference to a local array can go on the
>> stack but the array object itself goes on the heap.
>
> This does *not* describe the difference between a reference and an object.
> The reference can go on the heap as well the minute it is part of an
> object.
>
> What I'm saying is two fold:
>
> 1. You did not discuss /why/ there necessitates two components (reference
> and data), but that's ok, since your heart is clearly in the right place.
> I have no issues *at all* with your intent.
>
> and
>
> 2. It is nightmarishly hard to do, "depending". (as you seem to agree).
When a friend of mine asks me a question about how some
computer-technology works, I can preface the answer with "Do you REALLY want
to know?" and they've learnt that this a warning indicating that the answer
is very complex and long and that they'd probably be more blissful if they
remained ignorant.
In the case of how the Java memory/variable/storage model works, I try
to find out if they've worked with C, assembler or pointers. If so, then
it's usually straightforward to understand what Java is doing in the
background (ignoring optimizations performed by the garbage collector, the
details of which I am not completely knowlegeable myself either!) Otherwise,
I have to give them a basic introduction to how memory works in computers
(usually I restrict myself to the Intel x86 architecture), and then proceed
with the straightforward explanation mentioned earlier (again, omitting
details about optimizations).
With this strategy in mind, I'd like to ask the Original Poster the
following question:
Do you REALLY want to know?
In all seriousness, in theory, you don't need to know about these
details to be a "good" Java programmer, but in practice maybe people who
understand how the JVM works under the covers find it easier to deal with
otherwise difficult Java concepts. If you want to know because you think
it'd make you a better programmer, then I recommend you go all the way and
take a university level course in microprocessor architectures, do some
programming in MIPS assembler, and then ask your professor to conclude the
course with a broad generalization of virtual machines and how it relates to
the traditional writing code in assembler.
- Oliver
.
- References:
- how java variables are stored?
- From: rahul8143
- Re: how java variables are stored?
- From: Roedy Green
- Re: how java variables are stored?
- From: Roedy Green
- how java variables are stored?
- Prev by Date: Re: Can you detect if a class is mutable ?
- Next by Date: Re: Interface freeloading on a superclass - is it good practice?
- Previous by thread: Re: how java variables are stored?
- Next by thread: Re: how java variables are stored?
- Index(es):
Relevant Pages
|