Why do countries have the union jack?

Some Members of the Commonwealth which replaced the British empire retain the union flag as part of their countries flag such as Australia and Newzealand.