If I declare a variable static and compiled this class into a executable jar. If I start this class using batch file like this:
java MyClass
java MyClass
java MyClass
Would all 3 process share the same variable?
If I declare a variable static and compiled this class into a executable jar. If I start this class using batch file like this:
java MyClass
java MyClass
java MyClass
Would all 3 process share the same variable?
No. The static variable is specific to the JVM instance. More than that, in fact - it's specific to the class loader which loads the class. So if you created three separate class loaders, each responsible for loading MyClass (not just delegating to some common parent) they'd each have a separate, independent static variable in MyClass.