Beginner: Two simple questions

Discussion in 'Java' started by Floppy, Jul 14, 2003.

  1. Floppy

    Floppy Guest

    Hello,

    I was reading the chapter about vectors, and find out that every element is
    an object. Why does each element have to be an object?

    Also is there a program that shows the stack and heep as the program is
    running?

    Thanks
     
    Floppy, Jul 14, 2003
    #1
    1. Advertising

  2. Floppy

    ghl Guest

    "Floppy" <> wrote in message
    news:nuoQa.454100$...
    > Hello,
    >
    > I was reading the chapter about vectors, and find out that every element

    is
    > an object. Why does each element have to be an object?


    Vectors are "flexible" arrays, holding varying numbers of elements. What the
    vector actually stores is reference variables. Reference variables are used
    to reference objects. Therefore, a vector stores "objects" in a loose sense.
    In the technical sense every element of a vector is a reference.
    Once you understand this, you see that your statement "every element is an
    object" is wrong and leads to questions like the one you asked, which
    doesn't make sense.
    It's only a lazy way of thinking/speaking to say a vector "contains
    objects." A vector (and all the collection framework structures) contain
    references to objects.
    --
    Gary
     
    ghl, Jul 14, 2003
    #2
    1. Advertising

  3. Floppy:

    >I was reading the chapter about vectors, and find out that every element is
    >an object. Why does each element have to be an object?


    Object is the base class of all classes in Java. Each class extends
    Object, thus every object can be stored in a Vector. So there is no
    restriction when it comes to classes, if that's what you meant.

    On the other hand, no variables of primitive types like int, char or
    float can be stored in a Vector. That _is_ a restriction, which will
    be removed in Java 1.5.

    >Also is there a program that shows the stack and heep as the program is
    >running?


    Many IDEs give you the opportunity to check a variable's content while
    the program is being debugged. BTW, it's "heap" (just so you are more
    successful with web searches).

    Regards,
    Marco
    --
    Please reply in the newsgroup, not by email!
    Java programming tips: http://jiu.sourceforge.net/javatips.html
    Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
     
    Marco Schmidt, Jul 14, 2003
    #3
  4. Floppy

    Roedy Green Guest

    On Mon, 14 Jul 2003 02:23:15 GMT, "Floppy" <>
    wrote or quoted :

    >I was reading the chapter about vectors, and find out that every element is
    >an object. Why does each element have to be an object?


    The author could have written variants to contains ints, strings etc.

    However, Object was the most general. It can hold int if you put it in
    an Integer wrapper.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 14, 2003
    #4
  5. "Floppy" <> wrote in message news:<nuoQa.454100$>...
    > Hello,
    >
    > I was reading the chapter about vectors, and find out that every element is
    > an object. Why does each element have to be an object?


    Because of the way Java was designed. Primitive types are separated from objects.

    > Also is there a program that shows the stack and heep as the program is
    > running?


    It's called a debugger. There are plenty of free ones.

    /Jesper Nordenberg
     
    Jesper Nordenberg, Jul 14, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave

    Simple beginner questions

    Dave, Aug 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    352
  2. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    592
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  3. Rensjuh
    Replies:
    7
    Views:
    979
    Mabden
    Sep 2, 2004
  4. GenxLogic
    Replies:
    3
    Views:
    1,285
    andrewmcdonagh
    Dec 6, 2006
  5. superpippo

    Simple questions by a beginner

    superpippo, Dec 30, 2006, in forum: C++
    Replies:
    2
    Views:
    274
    Moonlit
    Dec 30, 2006
Loading...

Share This Page