The priority is based on what you choose to control.
Aperture priority - you set the aperture that you want - usuallly to control depth of field either shallow or deep depending on the shot. the camera then adjusts shutter speed to suit the chosen exposure level. In "A" mode the camera does not alter the chosen aperture.
Shutter priority - you choose the shutter speed - usually either to freeze or deliberately blur movement in the frame. the camera then adjusts aperture to suit the chosen exposure level. In "S" mode the camera does not alter the chosen shutter speed
Program Mode - The camera follows a programmed exposure value curve to select the correct combination of shutter and aperture settings. You can "shift" this program up or down using one of the rotary dials to bias the settings towards faster shutter/wider aperture or slower shutter/ smaller aperture to suit your scene but the camera will still endeavour to obtain the same Exposure value based on ambient light. (e.g f4 at 1/125th gives the same exposure value as f8 at 1/60th but f8 gives you more depth of field than f4).
Before deciding on on the shutter or aperture setting the camera first looks at the exposure compensation setting, exposure correction setting and ISO parameters. I will explain how these are used below:
1) Exposure correction - If you find that your camera typically over or under exposes all its shots then you can enter a correction in the menu. This compensates for a light metering systen that gives results either too bright or too dark for your taste. e.g. my D800 is spot-on but my D300 always over-exposed by about 1/3 stop in my opinion. I set the exposure correction to -1/3 on all banks to compensate. When you press your shutter, the camera first looks to see if any exposure correction has been set and adjusts the level of exposure it is aiming for.
2) Exposure compensation - The camera always aims to average the exposure overthe whole frame to a mid grey. This is effective for most scenes in daylight and gives a result that we perceive as similar to what our own eyes would see. However some scenes are naturally much brighter - e.g. on the beach, in snow, in white water, wearing pale coloured clothing - Any scene where a pale shade is dominant. Some scenes are naturally darker - e.g. wearing a dark suit, shooting a subject against a dark shaded background, sunset/sunrise where a dark shade is dominant. In a bright scene you need + exposure comp. to reproduce the brightness and the converse for dark scenes to reproduce the dark tones. The Ev +/- button is conveniently placed to allow shot by shot adjustments of the light metering target value for the camera. After checks for exposure correction in the settings menu, it will also check for exposure compensation settings and will add or subtract exposure value to suit.
Steps 1 and 2 above are used to generate a "setpoint" exposure value - i.e. the exposure value target that the camera wishes to obtain for the shot you are about to take. the camera uses this value in conjunction with the chosen ISO value to calculate aperture and shutter settings. The selection of ISO is discussed further in point 3 below because it is a bit more complex.
3) This is a complex topic, possibly requiring a separate post - I will discuss very briefly here: ISO - represents the "amplification" of the sensor output and just like stereo equipment, it comes with the penalty of increased noise at higher amplification settings - it amplifies everything, including imperfections in the response of individual pixels to light exposure. If you have fixed the ISO setting (e.g. 200) then the camera merely takes note of this in its exposure calculations. However, if you have set Auto-ISO the camera checks to see if the chosen settings will result in a shutter speed slower than the parameter you selected in your Auto-ISO setup. Under Auto-ISO - the camera automatically increases ISO (within preset limits) until a sufficiently fast shutter speed is obtained. This allows you to use your camera handheld (or freeze subject movement) in considerably poorer lighting conditions than would be possible at normal ISO settings.