Static methods and fields 00:00:00 Make a prediction You will separate class-wide data from per-instance state and recognize when shared allocation requires synchronization. Ticket one has number seven. Ticket two is created and the shared counter advances to eight. Should ticket one's printed number also become eight? No. The counter is shared allocation state; the recorded ticket number belongs to that particular ticket. Confusing them makes yesterday's ticket appear to change today. 00:00:29 A board game evening Four players sit at a board game. The centre of the board shows whose turn it is; each player keeps an individual scorecard. Writing the same central turn onto every scorecard would create competing copies. A static member represents shared state for its defined scope. An instance field belongs to one object. Pick the owner before asking whether either should be mutable. A static field belongs to the class. There is one, and all objects of the class share it. An instance field belongs to one object, and each object has its own. Some knowledge is about the kind and not about one thing: the value of pi, the number of sides of a die, how to read a date from text. Asking an object for it would be odd, and one would have to exist first. 00:01:21 Separate a shared counter from each ticket Create two tickets. Each stores its own issued number, but the sequence from which those numbers come belongs to the shared class or service. A new ticket asks for the next number; changing the counter does not retroactively change either ticket's stored number. If construction can happen on two threads, an ordinary increment can issue duplicates. Make allocation atomic or move it to a suitable identifier service. Start with seven issued tickets. The next ticket captures eight, then a later ticket captures nine. Ask the first ticket to print itself again: it should still say eight. Reading the current class counter during printing would incorrectly relabel every old ticket. 00:02:08 Prefer a pure static helper Converting metres to centimetres needs only the input and a fixed factor. A stateless helper can calculate it without storing anything shared. By contrast, a static current customer mixes simultaneous requests, so give that information a request-scoped owner. Multiply three metres by one hundred, then repeat the operation tomorrow. If the answer can change because a different shop used the helper, something unnecessary has been stored. This conversion can be shared freely because the answer follows entirely from its argument. Two threads can read the same counter before either stores the increment. Class-wide scope does not make an ordinary update atomic. If you only need deterministic conversion, a pure utility function avoids shared mutable state altogether. Java Math. A final class with static methods for numeric operations and the constants PI and E. No object of it is ever needed. Java Integer.valueOf. A static factory. The documentation says it always caches values from -128 to 127, which a constructor could not do. 00:03:23 Try an interview follow-up Is static int count with count++ safe? No, it is read, add, write. Two threads can read the same value. I use an atomic for one number, or a lock that is as shared as the field. volatile alone does not help. Two shops each need invoice numbers starting at one. A class-wide counter hands the first shop number one and the second shop number two. Give each shop its own sequence owner and test two instances together. A shared member is appropriate only when its lifetime and scope match the requirement. 00:04:02 What to take with you Static: one per class, reached through the class, no this. Instance: one per object. A static method sees static members only, an instance method sees both. Good: constants, pure helpers, static factories. Dangerous: static fields that change, hidden clocks and connections, utility classes that grow without end.