Usually this is done by means of Enumerated types. As someone who didn't get conventional CS education, Enums were bit of me-too for me, but the moment I realised they can be used to make invalid states unrepresentable, I was hooked.
Sure, they can be better in java, but they cover a large enough ground, and as always, most people find that sufficient.