I often hear the term "Stateless" and "Immutable". For example, HTTP is a stateless protocol, and a String object is an immutable object. But I have a hard time grasping the difference between the two. When I create a stateless object, it doesn't store any "state" data internally. And if I create an Immutable object, it mean its will never change.
Doesn't that mean the same thing?
Since the immutable object doesn't change, by definition it cannot have a state. It is what it is forever. And if an object doesn't have state, it cannot be mutated (by definition). Thus, aren't all stateless object immutable and immutable object stateless?
What could be an example of mutable stateless object or immutable stateful object?
No. They do not mean the same thing.
An Immutable Object can never change. That doesn't mean the data contained in that Object can't indicate State. It just means that if you want to represent a change in State, you need to create a new Object.
Stateless means that there is no state.