Plumbing Pipe Noise: Causes are expansion and water hammer

Why are my plumbing pipes in the wall making a knocking sound after I have turned on the hot water in the bathtub?