So I guess there are two parts, cause and how to fix it, so first causes:
No rim tape - sometimes new bikes won't have rim tape, and the tube can get slightly cut on spoke holes, if you don't have rim tape, put some in, it will save you in the long run
Rim has something sharp on it - rarely you might find that a rim has a little bit of metal sticking out that causes a puncture, generally this isn't a problem if you use rim tape.
Tube incorrectly installed - make sure that when you put the tube in that you pump it up a tiny bit, and move the tyre left and right and go round the whole rim like that(making sure that you can't see the tube), it will stop you getting the tube squished in between the tyre and the rim. If your tube isn't distributed evenly around the tyre you can also get a similar problem.
Tyre has something poking through or a cut - When you change the tyre run your fingers around the inside of the tyre, often there is something poking through, also inspect the inside and outside of the tyre, often there is a small cut, even a tiny cut will cause a road bike tube to fail.
Incorrect pressure - If your pressure is too low you are likely to get pinch flats, and if it is too high you are likely to get random failures. Make sure you check the recommended pressure on the side of the tyre. Pinch flats can in their worst case cut through the tyre as well, so if your tyres are low pump them up!
Cheap tyres - I have had quite a few tyres of different qualities, and it always seems that the cheap ones get some kind of cut in them quite quickly, but the mid range ones don't tend to get this. This mainly is appropriate to road bikes.
Tube Installation damage - You hear about people that damage the tube when installing them sometimes, just make sure that when you are installing the tyre the tube isn't between your tyre and the rim!
You didn't mention if you had a road bike or a mountain bike, but road bikes tend to cause a lot more problems with punctures, purely because the higher pressure will show up any installation problems and they will get flat quicker (or atleast flat enough to get a pinch flat).
How to fix it:
These days I don't bother repairing tubes, it quickly becomes a frustrating exercise, and in the end you don't want to be 30kms away from home with a leaky tube. If I got 1 flat I would replace the tube, and if I get another flat after that I would replace the tyre and tube. It seems really over the top, but it is very easy to put in 3 tubes into a tyre that has some kind of almost invisible nick in it, and it is cheaper to have just bought a new tyre and tube.
I guess for me it is more valuable to have a bike that will just work when I get out there.
Once you have read all that, you might want to have a read of Sheldon Brown's guide to flats.