I have a Java program 'Test1.java' which creates a static variable 'counter' and initializes it to 100. Later in 'Test1', the value of 'counter' gets updated to '200. I have another program 'Test2.java', which reads the value of the static variable 'counter' created in Test1.java. Problem here is that, I am getting the value of 'counter' as 100 always, and not the updated value. What should I do to get the updated value of the static variable from Program 2?
So, I'm not sure I completely understand your situation. Do you run the two programs separately? Or are both classes loaded into the same JVM together (like from the same .jar)? Your usage of 'program' may be throwing me off and you may be meaning you have two classes that are in the same program.
Hi Fiz, Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to comply with the JavaRanch Naming Policy. You can change it here. Thank you for your cooperation. Try posting the code so we can see what's going on. Be sure to use the code button and place your code between the tags.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
When you say "Later in 'Test1', the value of 'counter' gets updated to '200." - how is that actually coded? It is possible that you are setting a different variable with the same name and not realizing it. Can you show us the code?
"JavaRanch, where the deer and the Certified play" - David O'Meara