I notice a lot of developers use the static modifier a lot, I feel like they do this because it's easier or more convinient rather than have to change their OOP design to add their new variables. These are questions I like to ask myself before making a variable "static":

  • Is this variable ever going to change after being intialized?

                If the answer is yes I tend to stay away from using the static modifier. It's only my personal preference but I only like to use static for objects that remain constant throughout the entire program. If the static object is changing throughout the program process it makes writing new code for this variable difficult as you need to keep track everywhere it's being used. Also this is just plain bad OOP practice. Although nowadays what good OOP practice is still fuzzy to me I'm pretty sure this is bad.

  • Is this object thread-safe?

               This is a big mistake a lot of developers do when making object static. Developers try to be clever and save heap space by making things static. Remember this object now can now be accessed anywhere from the VM and if there are multiple threads bad things will happen if this object is not thread-safe. Good example is people making SimpleDateFormat static because "why would want to recreate a new object every time you need to format a date?" However many people don't realize this object is not thread-safe which creates random and weird results when using it. Even if the program your writing is single-threaded it's still good practice to not use the static modifier for non-thread-safe objects as it might create threading issues in the future if someone were to make a multi-threaded extension to your code.

Static variables have a place in the Java world, for variables that don't change like you know being STATIC!