Welcome to the workplace. Everyone, from the newest intern, to the most senior dev has the same issue.
After a few years of working as a developer what I've noticed is that senior devs either have too much pressure on them to experience boredom, or they've gotten very good at hiding that they're slacking off every once in a while.
Here's some things to keep in mind:
STOP CONSUMING COFFEE AND CANDY!!!!!!!
This is probably the biggest trap that office workers, and developers in particular, fall in. That sugar/caffeine rush sure makes time fly, and it helps you focus too! But you're endangering your health, and developing an addiction, and I'm not kidding when I use that word - sugar has been found to be more addictive than cocaine. Look it up if you don't believe me.
It's not a long term solution, and you will feel the consequences, as you start to pack on the lbs. Find a different way to clear your head and refocus. For myself, I'll get up and walk over to the kitchen for a glass of water. I'll chat a bit with whomever is around the water cooler, and maybe take a minute to look out the window in order to rest my eyes. I'll take a look at the newspaper on the cafeteria table. Last but not least, I'll maybe answer a question on Stack Exchange.
But cut the sugar and coffee abuse off right now! Believe it or not, healthy snacks such as a banana, or an apple can also "wake you up". Don't eat 20 apples a day though, as they contain quite a bit of sugar (fructose) as well. Everything in moderation.
You can't stay "plugged in" for 8 hours straight
You will have bursts of productivity and inspiration, while on other days you'll feel burned out and barely write a ling of code. It's typically exciting to develop system architecture, etcs. It's not nearly so fun to do the grunt work of hunting recalcitrant bugs in a few thousand lines of code (which is typically the territory of junior devs). Or developing unit tests, that's always fun, right?
Almost everyone procrastinates! There's very few people who naturally manage to remain focused on their task 8 hours a day, 5 days a week.
Now keep in mind, I'm not saying that slacking off at work is to be encouraged. I'm saying that it's natural for your mind to wander, and to sometimes not feel engaged in your work (especially the mindless, boring stuff that interns typically get assigned)
So why do some of your co-workers always appear to be working?
People typically focus because they're stressed
Most often when you're working on something there will be an expectation that you should finish within a certain time frame. The motivation and stress of getting done on time will be a pretty good motivator to keep you going (at least right before the deadline, when you'll panic, and suddenly feel very motivated indeed to find that last bug you've been putting off for the past week).
The more senior you are, the more fires you have to put out, and the more updates you typically have to provide. That will keep you pretty focused.
Advice
If you feel that you're underutilized, find a project you think could be improved. Identify a feature you could work on and speak to your manager about implementing a fix/upgrade on the side of your regular responsibilities. If you don't express a desire to do more they may not think you're actually capable of more.
In addition to going for a short walk, or chatting with a colleague every once in a while, try finding an innocuous activity that you can perform at your desk, such as taking 5 minutes to read the news, or a Stack Exchange thread. It will be a good way to clear your head when you just can't stand to look at another line of code.
Set daily objectives for yourself. The most difficult part of a task is getting started. Knowing that you have to dig into something you'd rather not be doing, break down the task into smaller, bite-sized chunks, and reward yourself for completing each one. For example, once you've reached your first goal, go for a short walk. Once you've reached your second, bigger goal, spend 5 minutes browsing Stack Exchange, or eat an apple while looking out the window and just spacing out. If anyone asks, you just needed to rest your eyes ;-)
Try listening to music, ebooks, or podcasts. I'm not advocating coming to work and slacking off for the entire day. However, having something like that playing in the background can help relieve the tedium of "working in a bubble", and feeling like you're stuck. Hearing a joke on the radio can lighten the mood.
Now I know what some of you are thinking: this is a guide to utter procrastination. And it can certainly be used to that effect, yes. It's up to each person to find that balance between simply relieving tedium and stress, and being a parasite who doesn't do anything at the office.