State and Path Functions
Both q and w are not the properties of the system. They depend on how exactly we carry out the transfer of energy. For example, we may transfer heat quickly or slowly and carry out the work involving finite or infinitesimal pressure difference inside the piston. We may carry out a given change in internal energy solely via heat transfer or via work done or a combination of both. Thus, for a given change in internal energy (dU), dq and dw may have varying values but the sum of these two will be equal to dU. In other words. dU is the state property (i.e. the property of the system as it has a fixed value for a given change in the system), whereas dq and dw are not the state properties (they are path properties).