It was explained like this:
HMS Javelin was launched as a 'K class' destroyer and HMS Kashmir was launched as a 'J class' destroyer.
The 2 ships changed their respective names, so Javelin became Kashmir and Kasmir became Javelin to be in line with class names (K class having names starting with a K, J class having names staring with a J).