Skip to content
Advertisement

How to keep a variable value even after doing run as-> Java Application?

I know that when we use static variables the value remains the same for all the instances of a class.

But when I do run as -> Java Application in a class, even the static variable is reinicialized with the default value.

Is there any way to keep a variable value even after doing run as-> Java Application in a class?

Thank you.

Advertisement

Answer

Save to a file, and read it when you want it again from FILE, I know that’s not a good programming standard, if it’s related to login credentials.

Static variables works only for runtime execution, so they won’t help and can store variables even after program terminates.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement