• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some Basic Doubts

 
subhadeep chakraborty
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am confused with some questions, please answer in a simple way so that i can understand...
1) why are wait(), notify() and notifyAll() in the Object class although we use it only while threading?
2) why can't static and transient variables be serialized?
3) what is the difference between a argument and parameter?

Thanks and Regards,
Subhadeep
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by subhadeep chakraborty:
1) why are wait(), notify() and notifyAll() in the Object class although we use it only while threading?

So you can synchronize on any object you wish to, since all objects will inherit those methods. If it were methods of Thread then you could only synchronize on the thread.

2) why can't static and transient variables be serialized?

The transient keyword is invented just to prevent the variable from being serialized. Sometimes a variable isn't serializable, but you can reconstruct it from other information (such as an InputStream). Without the transient keyword the entire object would be non-serializable.

As for static - it's an instance of a class that is serialized. Static variables are not related to the instance but the entire class. If you would deserialize it, there is still the existing information in the static variable.

3) what is the difference between a argument and parameter?

I think it's just a matter of name calling. I mix them up myself sometimes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic