I had knee pain when I was younger - I went to a physio who came up with some convoluted explanation as to why, and the long and short was that I did weights and cured the problem in a weekend. I was 30 but had had the problem since about 14. A couple of times since then it's come back cos I've gone directly from overworking sedentary couch potato to doing 10,000ft climbs in the Pyrenees without any preparation, but the preparation and the cure are the same - weights.
All the usual stuff e.g. keeping knees warm applies. I think worn joints - i.e. cartilage or bone damage - are very rare, the most common knee pain is caused by tendons. If that's the case with you then I recommend looking into weightlifting - you don't need fancy gear, I've strapped dumbells to a pair of defunct mountain boots and I lie on a sofa on my back with my legs hanging over the edge, knees on the armrest, and do a couple of hundred or so lifts, then still on my back I cycle in mid-air, and do a bit of side-to-side and in-out stuff. I'm sure it looks utterly ridiculous but it works. For the very rare occasion that the back of a knee hurts i do the same on my front - the options are less amusing but the principle is the same. Less weight and more movement is better than piling them up and straining. 6-8kg on each is plenty. I only need to do this when I'm about to go on a trek, or when I've come back from one that I didn't prepare for and therefore knackered my knees on the way down mountains with that 25kg backpack. Cycling has never messed up my knees since I started doing this - basically it was a one-off cure, and cycling has never again caused a problem. Once in a blue moon I get twinges at the beginning of a ride but they disappear when I warm up.
The kneecap should be a loose piece that you can wiggle around - in the bad old days mine was stiff, this is what the physio found - he said the kneecap should be loose and floppy - the tendons around it were stiff, and basically began to tear when under stress. The full programme should include deep-massaging them with very firm pressure, which I sometimes still do, to relax them and get blood flowing to maximize repair and regeneration. The physio also did other voodoo such as ultrasonic gizmos and electric current and stuff but I never found the need to go back to him for that - just weights, massage and yoga-style stretching did it, and I do all those at home for free (except the dumbells cost £20). I'm certainly not a body-building type but I have to admit that the weights are the single most effective part of it.
Ideally I'd have got a machine I sit on and straighten my legs in front of me and ropes and pulleys would lift the weights - but the dumbells method is so good that I couldn't be arsed with the expense and storage of the proper equipment.
PS about massage - some of the relevant tendons go under the kneecap - it's hard to get to them, and very unpleasant trying, since you hit a sort of funnybone (the one that makes your leg kick when you hit it) - but it's important to get in there and give everything a gentle pummelling to loosen it all up.
I hope I don't sound as though I'm trying to come across as knowledgable - this is just in my experience and it's been very positive, whereas knackering my knees regularly used to blight my life. If your sore knees are due to something else, a cracked bone or something, then the above may be totally irrelevant.