I share real-world lessons from building scalable systems at Binance, and running mission-critical cloud ops at GovTech and Singapore Air Force. No fluff, just practical takeaways, hard-earned fixes, and deep dives that matter.
Fields and methods declared with the static keyword belong to the class itself rather than to instances of the class. This allows us to use these class members without creating an object of the class. Static fields and methods are initialised and stored in the method area (part of the heap) during the class-loading phase, which occurs before the main program execution begins
A non-static variable or method cannot be referenced from a static context
When a static context is established (e.g., within a static method), it has no associated object instance. Therefore, it cannot access non-static members, as they don’t yet exist or may not exist at all. Attempting to reference a non-static member in a static context typically results in a compilation error.
In essence, trying to call a non-static variable or method from a static context is like trying to use something that hasn’t been built yet.