I want to increement a variable each time jvm loads the file or in other words i want to save the state of variable . Can anybody suggest how can i do so?
can anybody post the simple code for this. I googled for it but didn't got a small program demonstrating it.
well you can serialize an entire object, i e store values of all instance variables in a file , and can load it at will. you can find a simple program in Head First Java . Google also helps...
However, if you wish to save states of variables between every class instantiation,(and share them) you could simply make the variables static, and directly access the variables.... no need of serialization for this limited purpose...