To do this, turn your computer on while holding the "D" key. Then, you can run either a quick (probably 5 minutes) test or an extended test (over an hour... sometimes more depending on how much RAM you have)
This will test some major components in your computer... but most importantly RAM. The RAM failing is the most common reason for a kernel panic, but not the only reason it can happen.