• Post Reply Bookmark Topic Watch Topic
  • New Topic

Soem Questions....  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have these questions troubling me please help me...

1) Can i ever force GarbageCollection ?....Because in "Thinking in Java Ed2" its give that we can force ...is it true or i misinterpreted Authors explanation.
2)Is there any difference between the Storage area for static variables and non static variables ?
3) In a Program A i serialize an Object in to a file(A.txt) using Serilzation .I start another Program B and try to deserialize the Object from the file (A.txt) will the Object be reconstructed properly?

4) What would happen at backend when i call new Vector() or new MyClass() ?

Tx in Advance
Murali
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Muralidhar Gandepalli:

1) Can i ever force GarbageCollection ?....Because in "Thinking in Java Ed2" its give that we can force ...is it true or i misinterpreted Authors explanation.

Use System.gc() to force garbage collection.

2)Is there any difference between the Storage area for static variables and non static variables ?

This is undoubtedly JVM-implementation specific, and as such is at a layer that is abstracted away from the programmer (in other word, you shouldn't have to care about this... ). That being said, I can't imagine that there is a difference (all of these variables would ultimately be stored in the heap somewhere). I imagine that somewhere in the heap would be a "Static-fields-of-X-Class" object holding those static values, but I really can't say. Again, this is JVM specific, so I don't really need to say.

3) In a Program A i serialize an Object in to a file(A.txt) using Serilzation .I start another Program B and try to deserialize the Object from the file (A.txt) will the Object be reconstructed properly?

As long as both programs are using the same version of the class, it should be OK. I myself use XML instead of serialized objects, though, because its more stable (and human-readable in searialized form!)

4) What would happen at backend when i call new Vector() or new MyClass() ?

How do you mean, "backend?" In my lexicon, backend usually refers to a database, so I'm a little confused as to what you are referring.
I'll assume that you are asking what happens in the JVM, so I'll answer that.
When you do a new, the JVM determines how much memory to allocate to the object and allocates it. It then calls the constructors for that object starting with the most base class, java.lang.Object. Each constructor is called in turn, and if a constuctor is not specified, then the default constructor is called.
(Just an aside: don't use Vector. Use ArrayList or LinkedList or whatever, but Vector is not the thing these days...)
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use System.gc() to force garbage collection.

I was under the impression that we can only indicate the program's readiness for garbage collection to take place. Whether it is actually done is not at all in the programmer's hand.
Saket
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree to Saket.
You can never force JVM to garbage collect!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!