5 Replies Latest reply: May 13, 2008 8:47 AM by 807601 RSS

    what is the use of declaring  reference type of object

    807601
      {noformat}If we declare primary date type it will allocate memory for paticular type of date type varible.....but if we declare

      reference type for a variable what compiler do with it.......






      {noformat}
        • 1. Re: what is the use of declaring  reference type of object
          807601
          sandeepmalladi wrote:
          If we declare primary date type it will allocate memory for paticular type of date type varible.....but if we declare
          reference type for a variable what compiler do with it.......
          Date is a reference type in Java, so I don't understand your question.

          ~
          • 2. Re: what is the use of declaring  reference type of object
            807601
            sorry it is data,it is not date
            • 3. Re: what is the use of declaring  reference type of object
              807601
              sandeepmalladi wrote:
              If we declare primary date type it will allocate memory for paticular type of date type varible.....but if we declare
              reference type for a variable what compiler do with it.......
              The compiler will allocate memory for any variable. The difference is that primitives are held directly in a variable whereas objects are held indirectly via a reference. In Java no object is stored in a variable. It's always a reference that's stored. It points to the actual object.
              • 4. Re: what is the use of declaring  reference type of object
                3004
                sandeepmalladi wrote:
                {noformat}If we declare primary date type it will allocate memory for paticular type of date type varible.....but if we declare

                reference type for a variable what compiler do with it.......
                In all cases, declaring a variable simply allocates enough memory for that variable--4 bytes for an int, 8 for a double, etc., and for reference types, enough space for a reference. I think this is defined to be 4 bytes by either the JLS or the VM spec, but it might be that it's left up to the implementation.

                That detail aside, for reference variables, declaring the variable just allocates space for the reference, not for any object. As uj points out, variables don't hold objects in Java. The space for the object is not allocated until you instantiate it, usually with new.
                • 5. Re: what is the use of declaring  reference type of object
                  807601
                  OP - stop assigning dukes, getting your question answered, and not awarding them.
                  http://forum.java.sun.com/thread.jspa?messageID=10249429
                  http://forum.java.sun.com/thread.jspa?threadID=5291903&messageID=10234869#10234869