Is it just me or are most colleges teaching Java instead of C++ these days? I feel like I've been missing out with having zero classes teach or use C++ at all.

+5  A: 

It's been that way for quite a while; many of the Universities here in Australia teach Java over C++ because it's more mainstream - and modern. Mind you, when I went to Uni I got to do two semesters of COBOL and only one of C, so...

Mainstream means that having learned Java, it's a skill you can take out into the real world and apply to a corporate job. C++ is rarely used in greenfield development nowadays, replaced by Java J2EE.

Modern is desirable because things like resource management - memory handing et al - are the kinds of things that ought to be handled by the language, not the programmer. Programmers ought to be solving problems, not ensuring that every new is matched by a delete. That kind of argument is persuasive to the Lecturers who set syllabuses.

So I put it all down to pragmatism.

I'm sure that you're not endorsing it, but if you're constantly matching every `new` with `delete` you're probably doing it wrong unless the excersize is to understand pointers. C++ has smart pointers that are "garbage collected" and work without the headaches of "real" pointers.
+7  A: 

Colleges believe that Java is easier to learn and easier to teach. There is also a push to give students "real world" experience and in the "real world" Java Programming ability, regardless of real value, is generally considered to be more valuable to C++ programming ability.

I don't claim that this common belief is right, but it is prevalent among project managers and interviewers.

+1  A: 

I'd imagine better corporate uptake, better OO support and all round better exposure.

+1  A: 

It depends on the University. I think teaching core concepts is the most important part though: Java is probably a better language to teach programming/OOP core concepts with. C++ has lots of idiosyncracies that you have to learn about (or maybe less idiosyncracies and more that it's 'pure OOP'?), which would get in the way of the teaching.

That said, the University I'm attending started with C as the basic language and uses C++ to teach OOP. Java's in there somewhere though.

+9  A: 

I also think it's a case of Java has an ability to quickly bring forward the visual side of programming, of getting an app that really does something visually for the student to experience. C/C++ and a console app, just doesn't set most people's heart buzzing. Granted C and derived languages can do visuals pretty easily, but Java just does it faster.

In talking with teachers/professors at my school a lot of them said that the first CS course was to get kids hooked on programming, and a slick app is a really easy way to do that.

You'd think they'd do that by starting with Visual Basic. *shrug*
Kelly French
@Kelly: Most universities are allergic to proprietary software that costs money if there is an alternative that doesn't. Especially Microsoft for some reason.
@Joel: I would actually disagree with that based on personal experience, the universities I've seen actually prefer MS software since they get it for free or nearly free, amongst other reasons.
Most of the ones that I've dealt with have been partial to Linux toolchains, with Java as the initial teaching language, by YMMV
See BlueJ as an example of this trend.
+2  A: 

First of all, don't take a course that is only meant to teach you a language. Unless it's a completely different way of thinking from what you're used to, it'll be a big waste of time. Take courses that focus on algorithms and the like. If the material can't be applied to another language, then it's practically useless in the long run.

I imagine that the reason schools choose Java is because it frees them from having to talk about pointers. I could see that making the job much easier.

Ryan Fox
+2  A: 

This immediately made me think of slashdot rant threads.

+23  A: 

I think it's about levels of abstraction. Java is generally taught as an introductory course because as an introduction students do not need to know about things like memory management or pointers. Over a degree these abstractions are given more detail and students can begin to understand where abstractions leak.

+5  A: 

I think that demand from industry has played the biggest role. That is to say, demand from industry, filtered through the university bureaucracy, and mixed with pressure to keep up graduation rates.

Java is the easy choice. It's not as hard to pick up as C, it can't be called 'too academic' the way functional languages often are, but it feels ever so slightly more hardcore, than say, PHP. Personally I'd wish that my first year class (I'm in third) had been taught in Scheme, but I can just play with that on my own.

Rob Lachlan

I think it also depends on what school you go to. Some schools that may not have a focus on technical skills and lean more towards liberal arts or even just a generally larger college might believe that Java is easier to learn and has a quicker satisfaction. (Applets and quick programs that do things).

I go to a college known for engineering. Here the intro to the CS degree is taught with Python. Then OO moves on with Java, then Assembly and C.

However, the only CS the vast majority take is taught with MATLAB.


I was in the business school in college and our first programming class was C++. This of course was not C++ for majors, but it still gave me a bad feeling that I wouldn't do well in the class.

I think teaching core concepts is the most important part though: Java is probably a better language to teach programming/OOP core concepts with. C++ has lots of idiosyncracies that you have to learn about (or maybe less idiosyncracies and more that it's 'pure OOP'?), which would get in the way of the teaching.

Java tends to have a more universal feel to a business major that does teach better OOP concepts than C++. But then again, in my C++ class, we really only went through basic programming concepts.

My only Java class was my senior year when it was my "senior OOP" class. It was great at teaching me how to program the topics I learned in my Object Design class from my jr year.

Brian Childress

I think it's a combination of two things:

1 - Most jobs out there right now are Java. Schools look better by producing Java experts because they enter jobs without needing to be trained in the language.

2 - It's easier to teach a concept like Operating Systems or HTTP Networking when you can just focus on the concepts and not have the students worrying about things like memory management.

I finished college about 5 years ago, it was ALL Java except for a couple of specialized courses where C++ or C were used. For example in Game Programming we used Direct X, in Graphics Programming we used OpenGL, etc.

+14  A: 

I just finished four years at Virginia Tech as a Computer Science undergrad. My languages in coursework went as follows:

  • Java in high school, as the AP Computer Science exam had gone to Java that year.
  • Java for Intro to Object-Oriented Programming
  • C++ for Object-Oriented Analysis and Design
  • C++ for Data Structures (PR-quad trees, B-trees, 2-3 trees, binary search trees)
  • C for OS (extending PintOS from Stanford with userland programs, a filesystem, virtual memory, and multi-threading and dynamic priority scheduling).

All things considered, I think it's a great way to go about it. I learned object-oriented from the ground up, without a lot of language syntax (I'm looking at you, C++, and your pure virtual templated function syntax); I learned pointers and detailed memory management once I was comfortable with basic object-oriented principles, and learned to blow my foot off with C in OS.

Working now on OS X and iPhone applications using Objective-C and Cocoa, I feel completely comfortable handling high-level object abstractions in Cocoa, and handling memory with retain-release memory management in Obj-C.

In C++, member template functions cannot be virtual- pure or otherwise ;)
No functional languages? No Prolog-like languages?
Thorbjørn Ravn Andersen
+2  A: 

Java is, in a sense, easier to learn because it hides pointers from the programmer. It allows newer programmers to easily write programs that have dynamic memory for assets such as text, graphics, and input, unlike C++ where memory must be handled by hand or by using a smart pointer, which beginners may not know exist until they find them.

A second reason is that companies are writing programs in Java because of the easier learning curve which produces a larger pool of programmers to hire. Java will also run on any machine that has a JVM - Windows, Mac, Linux, and many cell phones as well. Write it once, run it everywhere!

However, there is a niche where the lower level capabilities of C++ comes in handy - embedded systems programming. Many such devices have memory mapped IO that cannot be accessed without using pointers, thus rendering the higher level languages nearly unusable.

In the end though, it should really come down to using the correct tool for the problem.

Cristián Romo
+4  A: 

The only languages I was "taught" in school were Pascal (this was 20 years ago) and 80x86 assembler. Every other language we used in school, we taught ourselves.

Java is a reasonable choice for an introductory programming course, but students who don't learn anything else are going to be at a disadvantage when they look for jobs after school.

Kristopher Johnson

Many universities also do not teach basic concepts such as pointer arithmetic and recursion. I was actually told by one of my professors not to use pointer arithmetic, but to use array index notation instead. What? Do they think that we cannot grasp these concepts, that they are too difficult? This is fine if all I want to do is go and write banking software, but what if I want to write the next programming language or a web server? I for one am very disappointed in the education that I have received thus far. If only I could go to MIT...

Ed Swangren
+108  A: 

I've discussed this with my professors. I've discussed it with people in the industry. I've even discussed it online, and if that's not definitive, I don't know what is.

I believe it comes down to 3 things.

3. Industry pressure

There's a lot of industry pressure to produce students who are experienced with Java. Companies are using Java a lot these days, so they feel the best way to get great Java programmers is to have universities teach Java.

Unfortunately, the concentration on Java has been to the detriment of the students. By giving students so much exposure to Java, they've reduced the exposure to other languages. The result is that most people who graduate with a computer science degree are not proficient in any low-level language (C, C++), nor are they proficient in any theory-based language (Haskell, Lisp).

Also unfortunately, it turns out that the industry is wrong. What they actually want are good programmers (code grinders are not hard to come by). Good programmers can use Java without any problem. The concentration on teaching Java has simply made it less common for student to be exposed to non-Java concepts. And it's really hard to be a good programmer if all you know is Java. Hence, the concentration on Java may actually be causing a decline in the number of good programmers being graduated.

2. Belief that high-level is better

There's a fairly pervasive belief in computer science that it's better to teach students high-level concepts than to teach them low-level details. Memory is a low-level detail. Pointers are low-level. Strings are (sadly) low-level. Objects are high-level. Object-oriented programming has become the ultimate goal.

With this mindset, it's easy to see that it's more important to understand the "concept" of a linked list than to understand the implementation. Sure, we have students implement simple linked lists. But they do it in Java, where memory is free and pointers are crippled. We also give them two weeks and enough reference material to cut and paste 99% of it. The end result is that many students don't really understand linked lists, which is why you'll see them two years later fetching every element of a linked list via a for-loop and the get() method. They missed the memo that this is really expensive. You'll see these same people concatenating strings in a loop, instead of using a StringBuilder or a StringBuffer, because they really have no idea what's going on. Thank God we saved them from all the low-level details about how things really work.

1. Declining enrollment

Computer science departments are scared to death about the falling CS enrollment. They got really spoiled during the .com bubble, and forgot that they are, in essense, a science. Their enrollment isn't supposed to match the English school. It's supposed to match Physics.

Since the bubble burst, there's been an enormous push at all levels of academia to keep enrollment high and to keep the graduation rate nearly as high. This means that they've knowingly simplified the curricula to keep from scaring students off. They really, really want to seduce people into computer science, so they are doing everything they can to hide the ugly details of the field. That means beginning courses use easier languages. It means that the students aren't graded, or pushed, as hard. It means that they have dumbed it down, because they don't know what else to do. They are afraid to push people out of the field, because they can't get enough people to replace them. The end result is that the entire field gets watered down.

Frankly, I don't envy computer science departments. On the one hand, I do think the quality of programmers would rise if they'd just push really hard at first. It would weed out people early, and allow them to raise the bar for the rest of the students. On the other hand, I think if they pushed harder, they would cause enrollment to plummet. This would result in a backlash from the university, from the industry, and from the government. No one wants enrollment to drop, but no one has come up with a reliable way to increase enrollment.

So they teach Java, and pray that most students don't quit.

Derek Park
Excellent answer! +1
Sadly, I have to agree with point #1. I've been teaching same second semester CS course for the last six years and I've seen a consistent decline in the amount of knowledge and skill that the students have acquired during their first semester. I don't however believe that this is a CS specific issue. More general skills like writing also seem to be declining. I think schools are, in general, loosening their requirements too look better (show higher grades than if they held the students to higher standards).
May as well link to the memo, or anything at all.
Preach on, brother! "[They] forgot that they are, in essence, a science." <- Bang on.
Derrick Turk
Derek, do you have references that actually show that colleges are turning to Java instead?
Andreas Grech
Andreas, I'm not sure what you're looking for. I don't have a paper to cite, no. I think it's generally accepted that schools are turning to Java. This is reflected in the TIOBE index, articles such as Joel Spolsky's "Perils of JavaSchools", experience hiring new grads, and stories from those new grads and current students. It's also reflected in this question. People wouldn't be discussing so much it if it weren't the case. Look through most schools catalogs and you'll find most of them using Java more than C++.
Derek Park
Programming is not a science. Science tells us how the world works. Physics is a science, building bridges is Engineering. Understanding what is computable is a science, implementing a spreadsheet is engineering. Learning to implement Tetris in Java is learning a craft.
Jose M Vidal
jmvidal, programming is a large field that contains both science and engineering. It's not an either-or proposition. It's both. Fundamentally, programmers need to learn a bit of each. A programmer who learns only pure science is ill-equipped to produce a working product, while a programmer who learns only engineering is ill-equipped to produce an efficient or useful product.I would also argue that the distinction between science and engineering is artificial. Engineering is applied science, but it is still science.
Derek Park
+1 very good answer.
Anders K.
Jeez, you sound like one of those televangelists preaching about one pure faith. As noted in other answers, it's nice to have different languages taught to undergrads and, all in all, java seems like a good starting choice.
Nikita Rybak
+11  A: 

The reason that first comes to mind is that schools are out to teach CS rather than 'programming'.

Java was chosen at my former school because it provided an easy way to start doing some real work quickly with regards to data structures and algorithms, while abstracting away the messy details of how a computer actually works that might be too much all at once for a first year student.

If you're a professor, would you rather spend the bulk of your student's time trying to get them to really understand a concept such as node manipulation in a B-Tree, or would you prefer they rip their hair out on top of this once pointers become involved?

Java also provides a nice bridge to other similar syntax languages in classes that are 'closer to the metal', such as compilers or OS.

On top of all of this, the java sdk is free for students to download, and there are popular tools such as Eclipse that are also free and will provide a uniform experience regardless of what platform their home machine is running on.

Well, GNU Compiler Collection (gcc, g++, gas and gdb) is free too (with all the source available for students to learn from); as for uniformity there's MinGW (on Windows).
+2  A: 

One answer is that Java has a less severe learning curve than C++, so there aren't as many syntactical and other gotchas in the way before you can get to learning the concepts.

I'd also say that C/C++ now occupy the space assembly language occupied 10-15 years ago, and Java/C# now occupy the space where C/C++ were.


I'm a college student just starting Progamming classes

C++ is what our school teachs for Progamming I class.


I recently had a friend in the business world ask me how he could learn to program. In response, I enthusiastically recommended Deitel and Deitel's "C++: How to Program". I believe that it is THE book to learn programming on. Think of my friend as Joe Student at University of So and So where the CS department doesn't believe in teaching the low level details. Is he at a disadvantage? Yes, but a recoverable one if he is willing to put in effort to go out of the box.

The disadvantaged need town criers though, because they don't even know their need to learn these things. The professors are telling them they should learn this and that, but not C++ and pointers--I remember reading a Java book once, and it failed to enter into the details of some of the class algorithms with the excuse that "some very smart people wrote these things so that we don't have to"; were they saying that as a reader of the book, I am not as smart as those?--so we have to cry out the need and we have to provide learning forums to recover our science.

In response, to both my friend and posts like this, I've called up my local school district and offered to get involved at the grade and high school levels to teach Deitel and Deitel's C++ book to kids.

Mike Caron

At University I was taught 1 year of Java, then a year of C++, then Java again in the 3rd year. Both are very similar.


I think Java is well suited for most general programming or software engineering courses. However, for courses on data structures (such as trees, linked lists etc.) that are made up of pointers, it seems irrational to teach them in a language which does not have pointers.

Fortunately some universities understand that (see CipherSwarm's post above).

+1  A: 

As a few other people have commented, I personally believe the reason many universities are going with Java is that is fairly easy to pick up and learn, allowing the professors to focus more on the theories and concepts behind our field. While I understand people arguing for universities to teach more languages, it takes something away when the student has learn syntax. If they know the concepts and ideas, they should be able to pick up just about any language. I also think that those students that want to be exposed to various languages, can easily do so on their own. Just my two cents (although slightly slanted since the University I attended mainly taught Java also).

+2  A: 

Here at the University of Colorado at Boulder, we use Python in the first half of the first CS course and C++ for most of the rest. I am glad that I am expected to deal with a systems-level language for the core courses like data structures and algorithms, having programmed in Basic, C, Java, C#, and others. Some more specialized classes like Operating Systems also deal a bit with x86 assembly.

I asked one of the professors about the language choices, and he talked about the following (paraphrased):

  1. Python is very useful in the beginning class because it has an interactive interpreter, so students can see what happens with short lines or snippets of code, which helps them quickly learn the basics of programming, while avoiding complexities like compilation. As soon as they start getting comfortable with Python, they start using C++ for the second half of the first CS course, so that they are ready for the later courses.

  2. Using a systems-level programming language teaches data structures and algorithms better because you can better understand how the code interacts with the actual computational hardware, and more so with using a bit of assembler code for students focusing on systems programming.

  3. Dealing with pointers, memory addresses, and manually managing memory is viewed as a vital part of the CS curriculum to produce students who know the finer details of computing theory and practice.

  4. The belief that it is easier to move from C++ to Java, C#, and so on than it is to go the other way around. Even though C++ is not the best language for many tasks, knowing C++ is similar enough to most other languages to pick them up quite easily.

Adam K. Johnson

I don't think C++ is any good. Beginners should be taught C. Then they can go and learn Java on their own if they want.

By doing this, they miss the formal introduction to object oriented languages. C++ can do all your neat C tricks, but you can splash OO in if you need to.
Wade Mealing
Why should they start whith C?
C is kinda cool I guess.
C is a reasonable starting language _for computer scientists_ because it teaches the basics - variables, loops, arrays, and pointers - without having tons of other stuff glommed on. For normal people, Ruby and Java are good choices for first languages.
Tony Ennis
+1  A: 

My first programming class was PDP 11 assembly. We learned the mechanics of memory management, pointers, and the difference between stacks and heaps. After that class it made you appreciate all the stuff going on when you made a function call, pushing onto the stack input parameters and the return address, etc.

+8  A: 

Having spent a lot of time programming in both C++ and Java I would say that it is because people recognise, consciously or unconsciously, that Java has lower accidental complexity than C++. Put simply, it is easier to get more done with fewer lines of code and that helps when trying to teach new concepts.

John Channing
First time I've seen someone say that Java makes it easier to get more done with *fewer* lines of code... And get away with it.
+1 for using the term 'accidental complexity'. Java has less inherent pain than C++.
Tony Ennis

I have everthing in the first year in C at the University of Sao Paulo (USP, Brazil) in my basic data structures course (and some logic gate programming in hardware class). Then in the second year VHDL (for hardware class) and more C (data structures II class). Now I'm starting in Java in my OOP class which is great to teach the concepts of OOP, C++ have many pitfalls that teachs very bad practices if you are inexperienced. So I think that Java is good, to teach OOP concepts.

I remember my first year, almost everbody in my class did not get pointers, they where completely lost. Took 2 months just so they could learn to build a simple list, but aftwards everthing went smooth, including binary trees.

At my university they teach concepts, not languages. How can you learn what a list is without pointers? How can you learn to deal with objects if you can program using the old paradigm by accident?

+1  A: 

As a general tip I think when looking for colleges for Computer Science you should look less into what languages each of the classes are based on, and instead what those classes cover. Ask a recent graduate if they feel they could pick up any language within a short period of time, and if the answer is yes then they most likely got a proper CS education.

I attended Ohio University from 2000-2004 and with the exception of an entry level pascal class it was all C and C++. It was most important that we learned how to program, use good practices, and solve problems. Syntax of different languages should be of little concern once you have a Computer Science degree from a solid curriculum. I have been a Java engineer for 4 years now.


It is easier for the professors

and students to.

The AP exam.

High Schools that provide the AP to their students have no choice. Colleges that accept the AP exam feel the need to use the language their students need to know.


There is a really good page talking about this: C++ in der Schule . Sadly, it is only in German, but if you understand it, it's worth reading.

Johannes Schaub - litb

Java instead of C++? Hopefully most colleges teach more than one language.

Java has its merits though. It's easier to work with, which allows people to focus a bit more on the stuff they're supposed to be learning, than on debugging segfaults and trying to get their code to compile. My college teaches Java in the OOP course, which I feel makes good sense. Java is built around OOP, while in C++, it is just one of a bucketful of options, all of which you have to master. They also teach SML before Java (as the very first course), as an intro to functional programming. And while we don't have a dedicated "C++ course", plenty of courses use it, so students tend to pick it up anyway.

I don't think it's an 'either or' question. Any decent CS college should treat languages as tools to be picked up when necessary, rather than trying to teach the One True Language. There are plenty of reasons why it's convenient for a CS student to know Java. It just shouldn't be the only language they teach.

+2  A: 

When I taught C.S., we taught Basic at the intro level, then Pascal. The main reason was ease of teaching. We shied away from C because, with very inexperienced programmers, there were too many things to explain, and too many ways to shoot yourself. C++ suffers from the same issues.

That is not to say C or C++ are bad at all. Personally I prefer them. But as a teacher, do you really want to be trying to explain to 18-year-old Suzy or Sam the difference between a character array and character pointer, or what a null pointer is, or even what a pointer is? As a teacher you prefer a "nanny language".

Mike Dunlavey
Heh, at 18 that's exactly what they did with us. I'd say that a person who can't learn pointers at 18 probably shouldn't be in computer science. While some _implementations_ that use pointers are difficult, basic effective pointer usage is not hard.
Tony Ennis
@Tony: That's what I thought too. What I thought were embarrasingly simple concepts that I could tell them in a class or two and then run out of material, those were major hurdles for them. Not because they were unintelligent, but because those concepts are intellectual "speed bumps" that, once you're past them they're nothing, but before you pass them they're incomprehensible. Teaching programming is a process of leading students over speed bumps.
Mike Dunlavey

I was in a somewhat unique situation when going through college. The first 2 years, my college was big on C++, so almost everything was taught using C++, and I really got to learn all the little details and mechanics of programming. Then starting my 3rd year, they decided to switch to Java due to industry pressure, so I had my last 2 years in a more high-level language, and got to learn things from that perspective as well.

It was somewhat awkward at the time, but looking back, I think it worked out well, as I sort of got the best of both worlds.


I have been taking classes that use C and C++ extensively. There are only 3 classes that use java in the entire department: the intro class, an undergrad level OOP class and an undergrad level DB class. After graduating, if I have to get a job that uses only high level languages, I would probably end up quitting and going back to grad school.

  1. Look at the job ads.

  2. Compare number of C++ to Java jobs.

  3. Profit!

Chad Grant

Java is simpler. So using Java is easier for students to catch the point they need to learn, instead of sinking into language detail...

+1  A: 

Talking with the professor at my current institution of higher learning who pioneered our migration from C++ to Java several years ago was rather enlightening. His staunch belief is that desktop programming is dead and everything is moving to the web where J2EE, JSP etc. tend to be major players. Hence to forth, students need to be preparing to go write web side code and java apps instead of messing with C++, pointers, memory leaks etc. After all, if it's a common data structure Java already has it built in. At least, that's why we switched from C++ to Java.

+1  A: 

As a semi new user to both Java and C++, and programming in general, and by new I mean 3-4 years of using it, my opinion may bring up controversy among people who have been in the industry and have more experience.

The courses offered at my institution have also been taken over by java(with the exception of anything dealing with hardware, assembly, and operating system design). The year before I arrived, there was a C++ programming course offered here, which I looked forward to taking. I arrived only to realize that they had canceled the class due to small numbers in our department and lack of faculty. Or what I like to call laziness.... As of now, our Electrical Engineering department offers the C++ classes and our Computer Science department strictly focuses on the Java framework, with the above exceptions.

Throughout my time studying Java, I have asked numerous times why my Department head and faculty have taken a route that has restricted us to virtually only learning java. I have gotten multiple responses that all have a common theme. For example, In one of my courses, "Enterprise Java", I asked my professor this very question and I received the response, "The Java.Net package is very easy for students to use, and does a lot of the messy work for the programmer, unlike languages like C,C++,etc. I didn't really think much of what he said so I let it go.

In another course I took using, Data Structures and Algorithms, I asked the same question and got the response, "The Java Library allows users to use ADT's from the Java library, so they don't have to worry about all the small coding details.

I could keep typing examples of me asking the question, but I'm hoping you are seeing the trend. In my opinion, although some libraries may be designed for certain functions or may be easier to use then others; this does not validate a reason to strictly use a certain language over the other. I do believe that Java is very useful for Web programming, and I do believe that its Data Structure definitions are very useful, but I don't think that these are reasons to teach the language.

Although I'm trying not to sound redundant to other responses, I feel that Java is well suited for an introductory language for certain reasons, but it would be very helpful to implement other languages into the introductory curriculum.

If nothing I have said has made any sense, then let me show you an example of why I wish I had been taught or was more familiar with C++ or C.

In my first day my programming language design class, I was asked a question about a block of code that contained a reference pointer, and I could not answer the question because I had no knowledge of pointers to that point in my history(3 years). Yet I am graduating soon top in my class. Something is not right....


Just pray they don't use ADA like my school did/does.

ADA, I have not heard that in a long time.
Tony Ennis

I think java is a fun language to work with. in java u don't need to clear memory for unused objects. the garbage collector is there to clear up. it actually reduce the work for a programmer.


From my point of view, I would choose another. Just imagine the first day, a hello world example.

In Java:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");

In C:

#include <stdio.h>

int main()
    printf ("Hello World!\n");
    return 0;

Think about what amount of knowledge you need to understand it. In Java, you need classes definition, method definition, static method, function call, arguments passing, arrays, dot syntax, string syntax ... In C you need #include preprocessor, function definition, function call, string syntax, return ...

My best first time language may be Python:

print "Hello World!"

It is simple enough to start with.

Didier Trosset
You were kind in that you didn't mention how to compile the Java, or jack with the classpath. And you didn't mention linking the C code. Python or Ruby (scripting languages) are a good first choice.
Tony Ennis
+2  A: 

As a school student in the UK looking at Universitys to go to for my BS, I have talked to professors a bit about it, as well as having talked to uni students.

Last thing I heard (Southampton, which is in the top 10 in the UK give or take) is that it was because it was one of the standard industry languages. Sort of makes sense, given how many Haskell jobs are there compared to Java. University's are also becoming a lot closer to industry, as most into lectures to CS departments always has a "We are working with IBM, Microsoft etc" or these recruiters come looking from company x.
I am not saying they are choosing Java solely because of industry pressure, but because it enables people walking out of their university to get a job. This is not just because they want their students to get a job but part of it is because it reflects on their rankings, which is going to be important to attract students.

It doesn't mean they don't teach things like Haskell, C, Prolog etc, they just most teach it first. Any competent person walking out of Uni with a BS in CS should be able to pick up any language given to them without to much difficulty, I don't think it matters what language you start people with. There will always be and have always been the bad, average and good. The good got a 1st and have no problems with pointer and recursion problems, which are the major things that Java doesn't teach.

Interestingly Newcastle (UK) is now starting with JavaScript next year, rather than Java. I haven't yet got around to asking why, but I would love to know the answer.

The side that supports your arguments that it is dumming down students is that I was talking to a 3rd year student (I think she got a 2-1) who I don't think had done any progrmming before she entered university who had said she had done her final project in Java because "it allowed her to create nice GUIs", which didn't say much for experience in other languages. (It wasn't a bad university either).

+1 for disclosing how it is you obtained your knowledge of the subject.
How does Java not teach programmers about recursion?
Amir Afghani
please convert to community wiki
Jason S
@Amir Afghani because recursion is not the centerpeice of the language, it's not the exaulted best practice, and it's not seen as necessary most of the time. In fact, it seems as though recursion is seen as overly complicated and hard.
I still don't understand how Java avoids recursion. Is it not an algorithmic methodology completely independent of language? Why would any other language require more recursion than Java? Also, when I walked out of my Java courses I new plenty about pointers even though we technically didn't use them the same way they are used in other languages.
Joe Philllips
Yes, you *can* do recursion in Java, but you do not HAVE to do recursion in order to do useful things. Never learning recursion properly is not an obstacle to getting useful work done in Java. I don't know how native recursion seems in Java, but I get the impression that it's complicated enough that people *do* avoid it and look for iterative solutions instead.
Well, any recursive problem can be solved iteratively (though it sometimes ends up being a royal mess), it's a proof from computation theory, recursion is particularly nice for theoretical reasons that would take me too long to get into and it's way beyond my expertise
@Amir, d03boy: Many imperative languages such as Java aren't optimized to handle recursion well, and provide other means to the same end (i.e. loops), whereas many functional languages, such as Haskell, are designed in a way that *encourages* and sometimes even *requires* you to use recursion (i.e. there is no such thing as a loop in Haskell, you must use recursion to iterate). Languages that are designed to support recursion well optimize it heavily to avoid performance problems and excessive memory use.
Mike Spross
@mike I would have made that point myself, but I wasn't sure whether java had tail optimized recursions. Are you saying it definitely doesn't?
@Breton: I'm pretty sure it doesn't. seems to confirm this.
Mike Spross
Whether Java handles recursion well or not is immaterial. Java can be used to teach the principle of recursion.
Tony Ennis
+5  A: 

This article by Joel Spolsky, one of the creators of stack overflow, addresses your question pretty well:

The Perils of JavaSchools

The article doesn't really answer the question, it's just bitching about the consequences of it.
With all due respect to Joel, does that give more weight to be a co-creator of stackoverflow? I mean, what's the point of mentioning it here?
Pascal Thivent
Woah, I didn't expect this to be the accepted answer - I just thought it was worth mentioning the article.
+3  A: 

I was at the University of Kent in 1997 when they switched to Java as the primary teaching language (from Modula-3). I believe Kent was the first university in the UK to do so (it subseqently became the the first Sun-certified Java Campus in Europe). It should be noted that, in a gesture completely unrelated to the switch, Sun Microsystems donated a shedload of hardware to the computing laboratory.

Dan Dyer
+3  A: 

FWIW, UC Berkeley (currently) and MIT (at least in the past) used functional programming languages, which I believe is the best way to go. I would argue, as would Abelson and Sussman (both experts in the field of computer science education), that the use of a language like Scheme (a sort-of dialect of LISP) allows for a strong understanding and a strong knowledge retention. From my experience and those of my colleagues, students who complete the "Structure and Interpretation of Programs" book by Abelson and Sussman are at a point where they can learn the basics of any programming language in a weekend, and a new paradigm in under a week (again, anecdotal, but I currently know 11 or so programming languages, and before I took that class I essentially knew no languages). Also, why do you believe that C or Pascal are of pedagogical value? Pascal has nice pedagogical features, C is rather abstruse for the beginning programmer IMO, and the syntactic hurdles can cause interference with the learning curve. I would be very interested in your motivation for advocating the teaching of Pascal and C, as I do research in computer science and math education, and new pedagogical theories, from the layperson or research scientist (in education) are always fascinating to me!

MIT just switched SICP from Scheme to Python:
I heard that... *sigh*... an incredibly wrong decision in my mind, but there are some excellent educational researchers at MIT, so perhaps they have a good point... I'd have to do more research on it
Actually, now that I've read MIT's thing, I definitely get what they're saying, and if they produce another book to teach with I must get it ASAP!
There's no point to learning Pascal in 2010 though taking it apart to see what makes it a well-designed language is a nice learning adventure. The point of C is to teach students how computers _really_ work. Modern languages abstract away too much hardware. In fact, that's the Java JVM's goal! Students should be versed in assembler, C (as a reprieve from assembler and to study the sorts of programs usually written in C, like operating systems), and then higher level languages that allow people to learn more, get a lot of work done, and get hired.
Tony Ennis
One subtlety, whether you teach C or not, or assembler for that matter, is highly dependent on the audience, I don't see a reason to teach C to, say, mathematics students that need to do moderate scale algorithms on matrices (for which Matlab will work fine and they won't need a direct connection to LaPACK). Similarly students who need to know symbolic algebra programming have no reason to learn C.
+6  A: 

As a student from a Java school (mostly), I'd say any student that's only learned a high-level language is going to be fine, as long as he's only working in high-level languages.

To draw a terrible auto-mechanic analogy, you wouldn't take an engineer that's been working on tractor engines all his life, show him a Porsche engine and expect him to be able to service it (unless he happened to have a Porsche at home that he tinkers with).

(In other words, if you're hiring for a C/embedded/C++ position, don't expect a pure-Java student that doesn't know any low-level languages to be what you're looking for.)

On a side-note, there are definitely fields of study within CS where low-level languages are more of a hindrance than a help. "Why is my neural network segfaulting?" (We wasted more time in our AI course debugging segfaults than actually learning AI concepts.)

On the other hand, knowing what I do from my schooling (C/Prolog/Haskell, some C++) has made me a better programmer overall (via different ways of thinking about things, more knowledge of what the computer's actually doing, ability to program efficiently, etc.).

edit: If I would push for anything, it'd be for a bigger focus on 'pure' functional languages. Haskell is a complete brain-bender when you're learning it, but it will change the way you approach any programming question.

edit 2: @Breton - yeah I got a bit offtopic there. The stated reason we were given for "Why Java?" was so they could focus on concepts and algorithms, rather than having to get stuck into the nitty-gritty of a lower-level language. The more cynical side of me suggests that it was so they could turn the washout rate into 25% first year, 25% second year, rather than having 50% of people failing an 'entry-level' course (my university still jammed C down our throats in second year and onwards).

Simon Righarts
This doesn't actually answer the question though. The question was "why?", not "What are the consequences?"
"Why is my neural network segfaulting?" - because you wrote it in C !?!?
James Morris
True, but nevertheless a great response.
Jacob Relkin
+1  A: 

Since I can't seem to comment on other answers, I will say this here. The link that Robert Harvey posted, at least from my brief scan, is so wrong as to be laughable in current educational circles. Anyone can be taught how to program, the evidence that they seem to be presenting in support of the proposition that many CANNOT learn programming is NOT solid in the least sense, and MUCH solid evidence for the proposition.

Read Papert, read Harel, read Blikstein, read any constructivist education researcher on the subject and it will become clear very quickly that, if the early statements in the link reflect the rest of the diatribe, that it is utterly false. Elementary school children have been taught how to program, as children at every other tier of the K12 process.

(disclaimer: I am quite connected to this topic as it is what I research at UC Berkeley)

(double disclaimer: No offense meant to Robert, I do not criticize you, I do not know your views on the subject, I do however criticize the writers of the paper, at least, with what little I know of the paper).

There has recently been much focus on that apparently the ability to program ties to the ability to create a mental model, and those who cannot do so from the start cannot learn it. "Can you grok pointers?" I cannot find the link right now, but I would like to hear if you have any opinion on that matter.
Thorbjørn Ravn Andersen
Unfortunately "grok" I think is a mistranslation or a typo... but about whether people can create mental models, I would say that it is quite possible that the correct "cognitive corridors" for exploring programming have not been utilized. By that I mean, the methodology of teaching and the way to approach the subject has not been sufficiently researched for certain types of programming (notably low-level programming). If you can help me with "grok", I can probably give a better answer!
"grok" is a term from Heinlein's _Stranger in a Strange Land_. It is never defined but seems to mean, "To understand _Completely_." I think I can teach anyone to program. However, some people just "get it" and some don't. The latter set would never be good programming colleagues.
Tony Ennis
+1  A: 

Given the historical context of the late 1990s, these decisions make sense. Java was the up and coming industry language, supported object-orientation in a clean way, featured garbage collection, and so on. It's not a bad first language, and if you teach C/C++ in systems programming and add in at least a couple more advanced languages you can probably strike the right balance between giving your students better chances in the current job market and preparing them for future developments.

You don't want to be a monoglot though, so if your school is mainly offering Java, try to take courses that use other languages (AI, systems programming, web, ...), or do some independent study, or even change universities.

Jim Ferrans
Just learning Java at a university is like going to the zoo and only looking at the elephants.
Thorbjørn Ravn Andersen
Great way of phrasing it! I think I shall commandeer that analogy :D
+2  A: 

I'm old enough to have used assembly first (1Mhz 8080) and then Pascal (2Mhz 8085). At that point, Pascal was an academic and an industrial language. IMO, the market moved to C on the basis of benchmarks. Run-time checks cost, and at a few MHz, matter. At that point schools still liked the academic roots of Pascal, and the run-time checks, but what were they going to do at the OO transition? I don't remember a widely supported OO-[oops,pascal] standard. Coming into this Java had some obvious strengths. On the technical side it was both object oriented and multi-threaded. On the pragmatic side it was freely available and fairly cross-platform. And there are jobs for it, as there were for Pascal way back when.

john personna
One of the nicest things in Turbo Pascal was when objects was added (except it was backwards, you only got inheritance if you explicitly asked for it). Only problem was it was too late and platform bound.
Thorbjørn Ravn Andersen
+6  A: 

I think it makes perfect sense to teach Java.

What would the alternative object-oriented language be? C++? That's a tough row to hoe if you've never programmed before.

Would C# be considered a worthy alternative now? Why would that be any different from teaching Java?

Java's a perfectly defensible balance between rigor and preparedness for work after university.

That should not be the only language that a student is exposed to. Certainly C, Lisp or Scheme, a functional language like ML, Haskell, or F# ought to be included in the curriculum. Python gives a nice mix of things and has some wonderful libraries. I would consider it an excellent choice.

I'd also say that exposure to a real data structures and algorithms class, numerical methods, compilers, operating systems, etc. should be an integral part of the curriculum.

The original question implies that someone is getting a computer science degree by simply learning the Java API and doing a few class hierarchies with Animal or Shape at the root. If that's the case I would object as well, but I don't believe it's true.

Didn't I hear Jeff Atwood say on a recent podcast that mashing up different bits was what modern programming was all about? Is Joel complaining about Jeff Atwood's skills because he's using .NET and not Scheme or ML or any of the harder languages that he had to suffer through back when he was going to Yale?

Joel's citation is five years old now. I'm not sure that it's 100% pertinent anymore. He sounds like he's turning into an old guy grousing about how easy young kids have it today.

Good answer +1! I personally would introduce a functional language before OO because I believe it promotes better programming practice earlier on (how many programs have you seen with the deadly, one enormous main function and that's it?). But Java is a pretty standard OO. They use it at Berkeley to help teach data structures, which sounds reasonable, but I won't be taking the class til a year and a half from now so I'm not sure :P
I agree that it is a reasonable compromise between academic interests and real-world needs. If you only can teach one, Java is not a bad choice.
Thorbjørn Ravn Andersen
While I don't do much old-fashioned procedural programming (notice OOP doesn't really eliminate procedures, it just wraps variables and procedures into objects as member variables and methods) these days, I think it's not good to teach an OO language as a first language. Computers (or, actually, processors) execute instructions one by one, thus, a good first language must be imperative above all. If you teach a freshman that using the Java API does the thing, he's never going to learn how that things works under the hood.
Eduardo León
@Thorbjørn Ravn Andersen, if I could only teach one language, I would teach a subset of C++. First, the legal C subset; second, classes; third, a brief exposure to templates (nothing as insane as the STL or Boost, though).
Eduardo León
STL? Insane? It's one of the best designs ever, emulated by Java Collections and C#. I would say STL is one of the best examples of how to use generics appropriately.
@Eduardo - why are object-oriented languages not good as first languages? They have the advantage of mapping to real-life objects. I think that's a help, far better than a functional language to start. The obvious rebuttal to "only Java" and not knowing what's under the hood is don't stop at Java, teach what's under the hood as well. I seriously doubt that you could write a C or C++ compiler; I'd bet that you've never written raw assembler for any processor. Does that mean you don't know what's going on under the hood? Your argument doesn't fly with me.
I agree that STL is *very* well designed, but it's not student-friendly. And I have written raw assembly for every x86 and x86-64 processor since the 8086. But assembly is not a good first language. A first language must be both imperative (as any assembly is) and procedural (as, unfortunately, no assembly is).
Eduardo León
I don't know what "not student friendly" is. Quantum mechanics isn't student friendly if you've never seen it before. Some topics simply require that the student rise to the necessary level. It's not appropriate for everything to be watered down to spoon feed students.
+1  A: 

Just my guess for the broader appeal of Java:

  • Java doesn't suck like C, i.e. it is a real high-level language, has a garbage collector and no pointer arithmetic.
  • Unlike Pascal, Java is object-oriented, which makes Pascal somewhat dated.
  • Functional languages are nice for a number of things, but an object-oriented language is better suited for many practical problems.
Functional languages are more pedagogically sound IMO, OO can rather easily be learned if you already know one programming language, starting OO seems difficult to me
Java doesn't suck like C, it sucks like Java.
All programming languages suck.
Thorbjørn Ravn Andersen
(and if you don't think Java sucks, then try doing "Real Work" without an IDE)
Thorbjørn Ravn Andersen
I am not saying Java is without flaws, but unless you write an OS and/or need to be really close to the hardware I think it's usually better choice than C. People who like the dynamic languages (e.g. Ruby) tell me Java is verbose, but within my IDE I hardly notice and there is hardly a reason to do 'Real Work' outside of it nowadays. And static typing makes writing tools so much easier...
Java (or any similar language, like C#) without an IDE is like fixing a car without using a socket set. Why would you even consider it?
Tony Ennis
I consider C's lack of garbage collection, and that it has pointer arithmetic, its _strengths_. When the situation calls for it, I'm glad I have C.
Tony Ennis
@Thorbjørn Ravn Andersen - I think Stroustrup himself said, "There are two kinds of languages - the ones that suck, and the ones no one uses."
Tony Ennis
@Tony - regarding IDE's, occasionally you have to fix something on the spot. Being able to handtype code and run it through javac and debug with jdb is a good thing. A _really_ good thing.
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen - if you need to do such a thing so frequently that is sours you on a language, then maybe it isn't the language's fault? Edit - that came out a little harsher than I intended. In any event, C or C++ would be no easier in the situation you describe.
Tony Ennis
@Tony, I program Java for a living, but that doesn't mean that it doesn't suck. _All_ programming languages suck. This includes BOTH Java and C++. But that doesn't mean that work cannot be done. I am just saying that you need to know the basics to be able to work well in a tight situation.
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen - I also program Java for a living. Yes, knowing the basics is necessary. I never said Java didn't suck. I said that the need for an IDE is _not_ why it sucks. I would go further to say the development of effective IDEs is why Java has progressed to nicely. Conversely, if we were all using vi/edlin/notepad/etc, I posit that Java would not have changed very much or might have faded away.
Tony Ennis
+1  A: 

Personal experience: They don't have professors which are experienced in C++ and therefore not able to teach it..


I am getting ready to graduate with a BS in Software Engineering and the only programming classes I have taken are Java I, Java II, VB.NET I, and VB.NET II. The only "C" exposure I had was with a project I was thrown into at the last minute in which team members had already picked their project (some stuff with OpenCV). Neither of my team members had any C++ experience either, and the project has been very difficult. I don't mind taking the Java classes, but I would really have liked to have some "C" experience, preferably C#. Why they taught us VB.NET over C# I will never know.


Because they are afraid of C/C++ pointers!


Java is better designed and has better support in terms of libraries and editors and tools. Java works well as a batch-processing program and as a web development program.

When I was in college, we were taught PL/I in our first semester. After that we were expected to pick up new languages on our own time. The professors would say, "We'll be using C this semester..." and that would be that. Except for C, all the languages we used back then have fallen by the wayside for the most part... COBOL, Fortran, PL/I, Pascal, BASIC, various assemblers...

If I were to recommend languages for new people to learn, they would be Ruby, Java, and C. A modern OO scripting language, a modern OO statically-typed language, and a decent language when it's time to get dirty. And if I could only pick 2, I'd probably drop Java out of the list.

Tony Ennis
-1 : They teach java because it's simpler to not shoot yourself in the foot. It hasn't got anything to do with better/worse, certainly not on the language level. IMHO.
Can you share any support for your opinion? Or is your downvote simply because you really like C++?
Tony Ennis
Ah that's why everything is written in Java: Windows, Office, IE, Firefox, Chrome, all the games, etc.. Performance?!
@Nils you'll probably find that more things are written in Java than in C++. (That being said, there are probably more COBOL programs than Java and C++ combined, heh.) Java is not my first choice when CPU performance is needed. As a business programmer, I have not lacked for CPU cycles in many years. The bottleneck is the database. (Which is something else probably written in C or C++.)
Tony Ennis
There ya go, I softened it up a bit.
Tony Ennis
@Tony: I removed my downvote. Note that I don't like C++ very much. But I like java even less ;-)