Replacement Freehub cassette
For the most part, yes, all Shimano and Shimano-compatible (SRAM, Sunrace, etc) 8-speed cassettes are interchangeable in terms of their overall length and fit onto the freehub body. However, hubs from the early years of cassettes might be either Uniglide or have the original Hyperglide freehub design that precluded use of an 11t cog. Much more info here.

Shimano comes up with different schemes for how the ramping, shift gates, and other design aspects of their cassettes are supposed to work together. The codes stamped on their cogs deal with what scheme that cog belongs to and what gear position it's supposed to be in it.