Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Beginner: Two simple questions

Reply
Thread Tools

Beginner: Two simple questions

 
 
Floppy
Guest
Posts: n/a
 
      07-14-2003
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


 
Reply With Quote
 
 
 
 
ghl
Guest
Posts: n/a
 
      07-14-2003
"Floppy" <> wrote in message
news:nuoQa.454100$. ca...
> 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


 
Reply With Quote
 
 
 
 
Marco Schmidt
Guest
Posts: n/a
 
      07-14-2003
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-14-2003
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.
 
Reply With Quote
 
Jesper Nordenberg
Guest
Posts: n/a
 
      07-14-2003
"Floppy" <> wrote in message news:<nuoQa.454100$ .ca>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two questions about style and some simple math Spoofy Python 2 01-20-2009 03:26 PM
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
Two simple validation questions Alan Silver ASP .Net 2 06-19-2006 01:47 PM
Two simple questions? NEWS HTML 6 12-19-2005 07:35 PM
two simple questions on CCNA ikrawal Cisco 2 11-28-2003 11:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57