Why are objects and variables stored where they are?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinothchandran
    New Member
    • Mar 2008
    • 2

    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
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by vinothchandran
    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

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      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

      Comment

      • vinothchandran
        New Member
        • Mar 2008
        • 2

        #4
        Originally posted by JosAH
        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

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by vinothchandran
          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

          Comment

          • sukatoa
            Contributor
            • Nov 2007
            • 539

            #6
            Originally posted by vinothchandran
            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

            Comment

            • satch
              New Member
              • Feb 2008
              • 23

              #7
              Originally posted by vinothchandran
              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?thr eadID=652356&me ssageID=3836043

              Comment

              Working...