In short; battling pokemon, either wild or that of other trainers in the game, earns your pokemon Effort Values, or EV's for short. Generally speaking, fast pokemon give speed EV's, high HP Pokemon give HP EV's, and defensive types (like Geodude) give defense EVs. There are also EV's for attack, special attack, and special defense, and some pokemon give two or more (up to three) spread across two different stats.
All Pokemon have a maximum number of Effort Values they can store, which will effect their stats upon leveling up. That number is ~512, which your party Pokemon will probably have by the end of the game. To be sure, you can go to Sunyshore city in Diamond/Pearl/Platinum and talk to one of the girls in the Seal Store. If your values are maxed, you'll get a ribbon.
When you use a Rare Candy on a Pokemon, they level up, but gain no effort values. So if you used 100 Rare Candies on a Pokemon, they'd have terrible stats. But Pokemon that have their EV's maxed out can be leveled up any way without any negative effects.
_________________
Sometimes I speak in walls of text. I will never be offended if you tear it down.
I believe I am cousin.