Teaching the basics of programming in Java

I’ve read a lot of postings recently denouncing Java as a teaching language. I tend to agree with that sentiment, but not because I have any particular beef with Java.

I’m currently studying in the Open University. I’m a high school dropout, I learned programming on the job and I’ve long felt that my CS knowledge is rather weak. That’s not to say I’m an especially bad programmer, just that my knowhow is limited mainly to practical, day-to-day business programming. I’m now trying to rectify that.

During these few months I’ve been studying (a few hours every week, an exam here and there) mostly subjects that I’m already intimately familiar with. Basics of programming. Programming in Java. Database basics. I have an upper hand over many other students.

I’ve also noticed that were it not for said upper hand, I’d probably have trouble learning how to program. Not because it’s inherently hard, but because the choice of teaching Java as a first language.

When you’re teaching the basics of programming, what you really should aim for is helping the students build a mental model of how things work. Focus on the what instead of the how. Java comes with a lot of baggage that makes it extremely difficult.


One of the first things I noticed people get from the lectures is that programming is really hard. You have to be real smart to know all this stuff. Even though the lecturer always says nobody is too dumb to be a programmer, he nevertheless skips a lot of things as too complex to explain. But we have to keep doing those complex, inexplicable things like wrapping every program in a public class MyProgram { } with a magic public static void main (String args[]) { }. Why is everything public? What does static mean? Or void, for that matter? Where does main come from?

Yes, I know, after years of programming it’s obvious. Java is object-oriented — or should I say, class-oriented — so everything must be wrapped in a class. Main is the entry point method by contract. Static things are specific to a class (whereas non-static things are specific to an instance). Public things are visible outside of your class instance and package. Void means we don’t return any value.

Try explaining that to anyone who isn’t a programmer. Now try doing that in a single lecture, and expect them to not only remember, but understand.

Or you could skip all that, and get everyone used to having a lot of “noise code” they don’t care about. After a full course of that, try to wean them off copy-pasta and explain DRY.

And then you can wonder why the students call every method an accessor. It’s because you’ve overloaded them with a bunch of terminology they don’t understand, and what sticks is what they hear the most. You keep telling them that calling getLength() is calling an accessor, and the example code has a 10:1 ratio of accessors vs. mutators or, you know, plain methods.

Take only what you can carry

How do you focus on the fundamentals of programming when you’re drowning in syntax?

If you can’t build a solid foundation, how can you begin to think you can teach good object-oriented programming? The students don’t understand how inheritance works, let alone what it’s good for.

The best example of getting it very wrong I can think of is one of the students, who in front of the class told everyone that the way he understood inheritance, the point was to gain access to the member variables of the base class, right?

Don’t laugh. Because nobody there did either. I was too stunned to comment at first. Then I thought I’d say it ain’t so because, dear Bob, this might be the one thing some of the students remember from the course. And then I thought, I don’t have the tools to explain this. My peers entirely lack the vocabulary for discussing such matters.

So it would all be better if we only used C#, right?

No, the problem isn’t how Java lacks this feature or that, and obviously the worst possible response would be moving to something that is basically Java vNext. The problem is how Java and its siblings force all of that complexity down your throat at once. It’s not a difficult language if you already grasp the basics –I’m ignoring the bits on purpose that would be considered obscure by a beginning programmer — but how do you expect to teach the basics like that?

finally { }

I’m having a hard time wrapping this up because I feel like I should have an answer. At the very least I should try to sell you my idea of the best teaching language. But I think for now, I’ll settle for trying to explain things to my fellow students as best I can. This spring, we have a programming exercise where we are supposed to independently build a simple Java app. I’m eager to see how that will play out.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.