• Post Reply Bookmark Topic Watch Topic
  • New Topic

life time of objects  RSS feed

 
w.k.hasintha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey genius java people ,
If we create objects from particular class ,are they volatile?
is this the reason why we use collections to store objects?
really appreciate if reply.
thanks
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your questions seem to be at a rather elementary level, so I am moving this question to our Java In General (Beginner) forum...
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
umm, collections are used, because they are more flexible than
arrays/vectors...

for exampe, in a doubly linked list you can sift fowards and backwards
in the list, due to the next and prev pointers...
unlike an array which only goes forward, until the end.

and in a circular Doubly Linked list, you can just make the last node
in the list point to the head node, and you'll never have to worry
about have a null reference, just have a 'isAtHead()' boolean method.

umm, i'm not sure if objects are volatile or not, but as far as using
different dataStructures, I think that has to do more with conveinance
of how the objects are stored, not storing them be cause they will "go away".

as far as I know, objects stay 'alive' as long as the program is running,
unless you delete certain nodes/variables, then the garbage collector should get them..

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
almost forgot, in collections, you dont have to have the same
data type in each node, which is not true with arrays..

Justin
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we create objects from particular class ,are they volatile?

No, the meaning of the keyword volatile does not have anything to do with creating objects.

is this the reason why we use collections to store objects?

No, this question is meaningless because the two things don't have anything to do with each other.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I "think" that the original poster means: if we create an object like this new SomeClass(), without assigning it to a reference variable does it just go "poof!" and disappear? Which it will do unless it hooks itself onto somewhere. Normally you must assign a newly created object to a reference of its own type (or to a reference one of its supertypes). Sticking a reference to the object into one of a collection's elements is then a logical thing to do.
[ October 17, 2006: Message edited by: Barry Gaunt ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!