Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Why is Java so popular as a first language to teach beginners? To me it seems like a terrible choice:

  1. It's statically typed. Static typing isn't useful unless you care a lot about either performance or scaling to large projects.

  2. It requires tons of boilerplate to get the simplest code up and running. Try explaining "Hello, world" to someone who's never programmed before.

  3. It only handles the middle levels of abstraction well and is single-paradigm, thus leaving out a lot of important concepts. You can't program at a very low level (pointers, manual memory management) or a very high level, (metaprogramming, macros) in it.

  4. In general, Java's biggest strength (i.e. the reason people use it despite the shortcomings of the language per se) is its libraries and tool support, which is probably the least important attribute for a beginner language. In fact, while useful in the real world these may negatives from a pedagogical perspective as they can discourage learning to write code from scratch.

share|improve this question

closed as primarily opinion-based by MichaelT, gnat, GlenH7, Dan Pichelman, Kilian Foth Sep 24 '13 at 9:03

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

you might find this thread helpfull: programmers.stackexchange.com/questions/24159/…, besides that Java compiled code is portable to other OSes which the rest are not as easily done. Plus someone thought that OOP is the only thing that needs to be teached...I dont agree. –  Marlon Mar 17 '11 at 4:09
Tons of boilerplate code? –  rreeverb Mar 17 '11 at 4:29
@rreverb: Java is arguably very verbose compared to a language like Python. The "Hello world" page at c2.com/cgi/wiki?HelloWorldInManyProgrammingLanguages is interesting… :) –  EOL Mar 17 '11 at 8:57
@rreeverb, read this: steve-yegge.blogspot.com/2006/03/… –  SK-logic Mar 17 '11 at 11:46
@EOL: Sorry, the "not liking Java" part wasn't meant for you, but for C2 contributors. (Their site is mostly: "we are so superior to Joe Average Programmer, that he should be legally forbidden to touch the keyboard; and all tools that make his life easier should be destroyed, because we don't need them.") I agree that 1 line in Python is simpler than 3 lines in Pascal, 4 lines in C++, or 5 lines in Java. Adding a strawman 19-lines Java code to make this point stronger doesn't contribute to a rational discussion. Shortness of code is good, but not the only thing in choosing the first language. –  Viliam Búr Sep 27 '12 at 7:21

7 Answers 7

One of the big reasons it is currently used was a push roughly 10 years ago to get colleges to "standardize" to something that's used in industry. Some went to a C based curriculum, (either C, C++, or C#) and others went to a Java based system.

Mind my playing of devils advocate here (This doesn't necessarily show my real opinions)

  1. Statically Typed is safer, one doesn't have to try and keep track of what something is, or what they may have accidentally changed it to (Java > Python).

  2. Not having to worry about the major flaws and failures of multiple-inheritance (Java > C++).

  3. Automatic garbage collection so the beginner doesn't have to worry about deconstructors and memory management in an age where computers have 3-4 GB of RAM, and most beginner's programs won't even come close to maxing that unless something is horribly wrong (Java > C).

It isn't so much that Java is inherently better than every language, it, just as any other language has some high points and some faults, the point is is that it's pretty decent at most things, giving a jack-of-all-trades type programming language to learn on.

share|improve this answer
While I agree that Multiple Inheritance can lead to really unmaintainable code, you can put it to good use, for example for mixins in python. You just got to use it right and that's where many a programmer failed. In general, you should not use Multiple Inheritance if you don't know what you are doing, but it can be useful if you know what you are doing! –  Falcon Mar 17 '11 at 8:15
about static typing: on the other hand, the time spent declaring types and working with a longer code in Java is usefully spent testing the program and fixing a few simple bugs, in Python, because Python code is often 2-10 times faster to write than Java code. :) –  EOL Mar 17 '11 at 9:01
@EOL Don't you think that some people will be confused, that they are forced to find problems in software written in language they are just learning? Especially that error messages themselves tend to introduce a lot of new concepts (stack, exception, dereference etc). –  Jacek Prucia Mar 17 '11 at 9:13
@Jacek: My experience as a Python teacher (to graduate students) is that there is even no need to teach them about Python's error messages: they understand by themselves where to look for problems in their code. (Teaching them about Python exceptions is useful in itself, though.) –  EOL Mar 17 '11 at 10:04
@EOL Yeah, I'm just playing devil's advocate with those, I personally detest Java, it's bloated and fairly unfriendly, but I'm appreciative of other languages because of the fact that I had to deal with the most mediocre of programming languages in all categories. I love my python and perl for fast "scripting" and my C for heavy lifting, and I don't think I would like them as much if I hadn't done years of Java in school to really make me appreciate their strengths. –  Jeff Langemeier Mar 17 '11 at 18:09

Although I don't consider Java the ideal beginner language either, it does have a few points in its favour.

  1. Garbage collection: For a complete beginner, dealing with memory management is a big distraction that he can do without.

  2. Strong Typing: catches many newbie mistakes. Also true, to a lesser extent, for static typing.

  3. Somewhat simplified OOP: Java lacks some of the cooler/hairier concepts of OOP found in other languages, like multiple inheritance, operator overloading, and even a first class function type. Gets in the way for many experienced coders, but a lot of work reduced for the beginner.

  4. Single paradigm: You mention this as a weakness (and I agree it is), but for someone just learning OOP this is actually a plus. Java forces the programmer to use OOP, otherwise it will just not work. Also, when a newbie looks at Java code written by someone else, it is guaranteed to be object oriented. In many other languages (e.g. Python, Ruby), there is not real guarantee - and the beginner can easily get confused looking at code that is not object oriented by design (which he will not be able to recognize as not object oriented) and get a wrong view of what object oriented means.

Apart from all that, having a well stocked library is a big plus even for a beginner. It lets a beginner make cool/fun things with a minimum of fuss and stay motivated to learn about the deeper things.

Having said this, I do not think Java is the best language to start with (or even the best language to learn even after you've learned 1,2,...,n languages ;) ). But I do not consider it to be a bad language for a beginner. There are certainly much worse.

share|improve this answer
While I agree with your points, I would say that you can get them and more (including simpler and more legible code) with Python, for instance, which is a reason not to teach Java as a first language. –  EOL Mar 17 '11 at 9:03
@EOL: Which is why Python is what I recommend to first timers. But Python having some advantages over it does not take anything away. The OP seems to be thinking Java has no qualities that make it a choice as a first language, just pointing out that that is not true. –  MAK Mar 17 '11 at 9:08
thank you for pointing this out. Glad to see that we're on the same wavelength. :) –  EOL Mar 17 '11 at 10:06
I think it is a crime to teach OOP as a first paradigm. –  SK-logic Mar 17 '11 at 11:58

Correct answer would be: It was the first language. The first language, that students learned in college, that is.

Teachers in colleges and universities have moved on, though. Most use Python or C# to teach students "how to program".

I had to learn Java at university, and never used it outside of it. I use C++, C and Python, as well as a lot of shellscript.

I do a lot of C and C++ programming, but I still feel the urge to come back to Perl sometimes, as I'm using Perl for well over twelve years.

I concur with the latest trend in colleges, though. Teaching Python as first language, is a good starting point, I believe.

share|improve this answer

I think reasons 2 and 3 are in direct contradiction of each other. I don't know of any languages (but I'm not claiming to know all) where you're doing low or high level programming and its easier to learn than java. If the audience is budding programmers than they need to get used to the "tons of boilerplate" sooner or later and of the more popular choices (Java,C,C++,C#,etc.) Java is by far the one with the least "boilerplate". Another good reason to get a foundation with Java is the rapidly increasing job market for Java Programmers. Its used EVERYWHERE!

Overall I think its a great language for beginners unless perhaps they're just taking it for exposure and nothing more than by all means whip out the visual basic... we already have way to many "programmers" who really aren't! lol

share|improve this answer
Everywhere is not the answer, or we'd all be using C –  Daniel Little Mar 17 '11 at 6:43

why? Because it's cheap. Free compilers and IDEs, tons of websites with free tutorials to use instead of expensive books (or even better, for the teacher to leech and use as material in class instead of writing his own curiculum), and of course you can just point the kids to some forum to post their homework questions, freeing the teacher from having to answer them (or so it quite often seems visiting Java related forums).

share|improve this answer
This is pretty much the same argument for Python, except Python doesn't need an IDE. Learning an IDE is just another barrier to learning programming. –  tjameson Feb 20 '13 at 17:13
@tjameson you're wrong. Java doesn't NEED an IDE either, but you're a lot more productive with a good one. Same would be true for Python. –  jwenting Feb 20 '13 at 18:29
Since Python is interpreted, development is as easy as Edit->Run. With Java (and a multi-file project), you need a complicated make or ANT file, which needs to be updated whenever you add a file. Not with Python. Most developers use an IDE for Java development, but I've never met a developer who uses one for Python. –  tjameson Feb 20 '13 at 19:09
you don't need anything you wouldn't need for a similar sized python project. But python doesn't support any large scale development so people don't even try to make tools for it :) –  jwenting Feb 20 '13 at 20:36
No large scale python development? (More here) –  tjameson Feb 21 '13 at 0:44

At my university, Turbo Pascal was the language of introduction until the year after I started, when Java took over - so I saw the introduction of Java to first year students as it happened.

I actually looked at some of the new Java lecture materials for some of the same classes I did the previous year in Turbo Pascal. The reason why they did it seems to be that Java is a relatively elegant language for introducing OO concepts early, and high level enough not to get bogged down in low level concepts that would do first year students' heads in.

Note: I'm not saying I agree with this, just that this seemed to have been the reasoning why Java took over as a common introductory language around a decade ago.

share|improve this answer
Why is Java so popular as a first language to teach beginners?

I think it's not Java. C++ is much popular as the language for beginners to understand.

share|improve this answer
C++ was also the reason why many people hate programming, I personally think teaching C++ as a first language is a huge mistake. –  Mahmoud Hossam Mar 17 '11 at 7:11
I agree. When I first learned it. It took months for me to understand some concepts like Pointers. –  Nipuna Mar 17 '11 at 7:14
what's even harder than pointers is being able to actually use them properly in non-trivial programs –  Mahmoud Hossam Mar 17 '11 at 12:07
Then after pointers, someone throws you into some code using templates. Not the best experience. For this very reason, I prefer C to C++ for teaching engineers. –  tjameson Feb 20 '13 at 17:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.