First, are you taking notes? If not, I would recommend doing that - actually writing down the information should keep you on topic and keep your brain from wandering. If you're already taking notes and it's not helping, perhaps switching to a different model, for instance mind mapping, might help.
That said, it's a bit difficult to provide an answer when I don't know the details of your problem (see my comment on your question). Why are you having difficulty concentrating? What are you doing instead?
It might be some simple physical reason - you're hungry, or falling asleep, or sitting next to noisy classmates, or feeling restless because you get no physical activity - any of those should be simple to fix.
Maybe you just don't find the material interesting at all, or don't understand why you need to learn it. If that's the case, try talking to your advisor to get a better picture of why the classes you're taking are important (or dropping one or two if they aren't!), or possibly consider switching majors.
Maybe the material isn't on the right level for you. If it's too complex, you might need to do a bit of studying on your own first to be in a better position to appreciate the lectures (read the relevant textbook chapters, or perhaps ask the professor for what the best material would be). If it's too simple, you could skip some lectures altogether (if that's allowed), or sit in class but spend the time studying more advanced topics (or, if it's a discussion class, steer the discussion toward more advanced topics if that's acceptable).
I'm sure I'm missing some other possible reasons.
You might also want to give the answers to these questions a look (added two more):
- How to focus on a long class?
- My thoughts distract me, how do I keep my focus?
- How to prevent/control daydreaming?
Edited to respond to new information:
It sounds like you have two problems right now: A, you missed a lot of material and are behind in your classes, and B, you can't concentrate. Before you can figure out a solution to B, you have to deal with A - you won't be able to concentrate on material you have no background to understand. So you need to do that. Re-read the textbook chapters that cover the lectures up until now, and do the exercises; go over the lecture notes if the instructors make them available; ask to borrow your classmates' notes; talk to the professors or teaching assistants if you need more help.
Once you've caught up on the material, it seems that there are several things you can do to try to improve your concentration:
1) Take notes. Really, this is very important to be doing in most cases if you want to retain the material, and it's the easiest way I can think of to keep your mind on track.
2) If you think part of your problem is that you're restless due to physical inactivity, fix that. Find a good way to set up an exercise routine. Sign up for a PE class you might enjoy, if you have that option!
3) If catching up by reading the textbook and doing the exercises worked well for you, perhaps you just learn better by reading than listening. I'm like that - in college I skipped more than half the non-discussion classes (especially math), used the textbook and lecture notes, and got mostly perfect grades! If this turns out to be the case for you too, you could skip the lectures (if allowed), or just take your textbook along and read it in class, or just go to the lectures anyway but then make sure to review the textbook material to really make sense of it.
4) I think you should talk to someone in your program about how your classes are useful and whether the material in higher years will be more interesting to you. If you have an academic advisor, or a counselling center, or even a professor you feel is approachable, they should be the person to talk to - if not, try talking to some older students in your department. If you really don't find the material interesting, perhaps programming just isn't the job for you, and it's much better to find that out now, when all you have to lose is less than a year of college, than when you're a year or two into your first job!
Also, if it turns out that you're so far behind that you can't catch up in all your classes (although hopefully that won't be the case!) - is there an option of re-taking some next year and postponing your graduation by a term or a year, or is that not how the system works? Or maybe doing some classes over the summer? Surely there's something you can do if you've fallen off the regular schedule. Again, talk to an advisor or someone else who can help you figure that out.