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.

I'm in the throes of getting myself enrolled in school to get a CS degree. The school I am looking at actually offers both Java- and C++-based for the introductory software development courses (object-oriented programming, design patterns, that sort of thing). It is student's choice which track to follow, but there is only time to follow one.

Knowing what you know now, if you had the choice, would you lay down your CS curriculum foundation in Java or C++?

My current debate currently looks like this:

A good friend (who has a PhD in AI) is touting Java as the better choice regardless of what I do, if only to open up more job opportunities later, though he might be biased since all of his work has been in Java (he loves it). I live in the Boston, MA, USA area and I see an equal amount of Java and C work.

On the flip side, although I haven't entirely yet settled on what I want to do with the degree when I'm done, my preference would be to develop for the Mac, which I am doing now albeit in a limited capacity. To that end, I'm getting some limited exposure to C++ already, but I've had none with Java, and looking at my projects at my day job I don't see a need to use it anytime soon, "soon" measured by at least two years.

I probably should note that I'm an adult going back to school after 20 years (I currently have no degree of any kind) so I'm looking to maximize the opportunity and time spent as best I can. I'm kind of leaning towards C++ but I'm still ambivalent, and some outside, objective advice would help here.

Or I could just be thinking too hard about it.

UPDATE: It turns out the language selection wasn't so clear cut as I originally surmised. While a couple of core courses focused on Java, some of the other core courses work in primarily C and Java, but also a few others thrown in for good measure. In fact, my rest of my semester is going to be in Objective-C after spending time in Java and Javascript. Last semester was C, Javascript, and PHP, plus a few others thrown in as assignments required. Since things were pretty much split down the middle overall, and I am still getting answers to this, I am now trying to work my curriculum such that I meet all of the requirements for the degree but to absorb as many languages as I can reasonably handle. So far, my grades have not suffered trying to do this.

share|improve this question
1  
Everyone in the academic research environment is touting java right now. Also, regardless of language you need to learn from university how to learn new languages. C++ is around as is java but there is not assertion they will be in 5 years. New languages/technology are always coming so you need to be prepared to pick them up and become adept quick. –  Chris Nov 4 '10 at 19:15
1  
@Chris: Which is why my recommendation would be to learn something that facilitates further learning, rather than something that's popular now. I'd recommend either C++ or Python rather than Java (obviously for different reasons). –  David Thornley Nov 4 '10 at 20:15
    
It is not that language that matter. It's the abstract concept. Get the concept right, so the students can easily learn anything later in his life. –  J-16 SDiZ Nov 12 '10 at 4:59
1  
I'm in an (eerily) similar situation: going back to school for CS after 20 years away from school. My school also has a Java/C++ split track. After reading everything here, and even giving +1 to the top answer, I'm still going to go with Java, and here's why, in case it's helpful to you: I'm coming from web development (Javascript, PHP, Python), so the support of the Java libraries is a plus. Assuming I also take the time to really capture the OOP principles, I don't think moving to C++ (if necessary) will be that hard. Java is the middle-ground between scripting and compiling. –  b. e. hollenbeck Nov 18 '10 at 17:03
1  
I think I disagree with every answer. It really doesn't matter. You will learn similar concepts in both languages, and you will learn the other language you didn't choose and others as well through your studies and career. –  Matsemann May 13 '13 at 12:35

10 Answers 10

up vote 51 down vote accepted

I'd personally go with C++ as it will give you insights into how parts of Java work under the hood (Pointers for example). Moving to Java from C++ is fairly trivial, whereas moving the other way around is arguably more difficult.

The truly difficult thing about the Java eco-system is it's vast number of frameworks, libraries etc - they're unlikely to cover all of that at University anyhow.

At the end of the day it's not going to matter that much what language you choose, as long as you learn the principles.

My JUG is going to kill me for endorsing C++ ;-)

share|improve this answer
1  
+1 for excellent point about size of Java eco system and the transition explanation. –  Jas Nov 4 '10 at 18:43
1  
The problem with learning a big eco-system at a university is that that won't be useful throughout your professional career. You're better off learning fewer libraries and learning concepts or getting familiar with actual language features. –  David Thornley Nov 4 '10 at 20:14
2  
One further jump-off for C++ is that you could then do managed C++ on the .NET Framework, giving you a lead-in to learning C#, F#, and any other language on that runtime. Java also has great lead-in to the JVM, and languages like Scala, but there's no JVM C++ that I know of. –  CodexArcanum Nov 4 '10 at 21:05
    
As someone who likes to think he's pretty decent in C++ (and Java), I don't think any modern introductory programming course should be in C++. It's simply too difficult. If the university doesn't teach C++ at all, move along, sure, but for an introduction I'd go with something simpler and prettier like Java. Maybe if I didn't think they're all evil, I might even have recommended a dynamically typed language. –  Dukeling May 13 '13 at 12:43
    
Back in some of our days before Java we didn't have this choice and we all learned C++, so I dont' see any problem with people still learning C++ first. I guess intro in Java is better than intro in Turbo Pascal. –  Bratch May 13 '13 at 17:40

I think the bigger question to ask yourself is do you want to be a good programmer or focus on computer science. If CS is your goal and you want to be on a PHD route then perhaps Java is the way to go. Java provides the Java collections classes, which have lots of premade data structures and algorithms. The advantage of this is twofold: First is that you get to play around with the data structures and algorithms to see what they do before worrying how they were constructed. Second, this provides the professors more opportunity to teach CS principles that use data structures without having to worry about the nitty gritty. Later on they can go back and have their students create the structures from scratch.

C++ on the other hand is a lower level language. It forces you to consider pointers and garbage collection. The learning curve is a little steeper but in the end when you find yourself down the road programming with external frameworks you will feel less like you are just relying on hidden magic. Furthermore, many larger companies are still using C++. It is more difficult to go from Java to C++ than C++ to Java.

share|improve this answer
    
Right now, my goal is to just get into software development, so become a better programmer. I have little interest in far-reaching academic pursuits at this point. –  Philip Regan Nov 4 '10 at 19:41

I have to disagree with most people advocating Java here. Learning C++, even if you haven't studied computer and microprocessor architecture, gives you so many invaluable insights in the way computer programs work and operate.

Nota bene, I'm NOT advocating you shouldn't learn Java (better yet, C#) because these are modern , rapid application development langs and huge frameworks have been built around them giving you access to a lot of "free" functionality, like abstracted file access and similar, however a true software engineer should know at least some C++, C or at least assembler, because that's what separates you from the script-kiddie types.

Once you are reasonably proficient with C++, confident with memory management and STL, picking up Java/C# should be a breeze.

share|improve this answer
    
Agreed, I'm positive that learning Java if you are already proficient with C++ will be much, much easier than learning C++ if you are already proficient with Java. –  Carson63000 Nov 4 '10 at 23:59
    
The problem with becoming "reasonably proficient with C++" is that it will take years and you will still only learn a tiny subset of OOP. –  Henry Nov 11 '10 at 22:41
    
Java is not a rapid application development language. It may be slightly higher-level than C++, but it's nowhere close to the abstraction level of Python, Ruby, Perl, or Visual Basic. –  Evan Kroske Dec 11 '10 at 21:20
    
@Evan - Yes, Java is a "rapid" development language if nothing else for it's vast libraries (It is commonly said that any Java dev has Java API docs open while working) as well as not having to do manual memory management. And the man who designed Java, designed it because he wasn't getting anywhere using C++. Plus the sheer number of deployed Java apps to-day (lower entry barrier) is another argument for it's "rapidness". –  Jas Dec 11 '10 at 21:54

I'd recommend C++. I had some classes in Java, and some in C++ in college, and the language specific skills I learned from C++ have helped me more when learning additional languages later. Additionally, although I see a lot more Java than C++ job openings, most are looking for a full Java stack, like:

  • EJB 1.x/2.0, JNDI, JMS, JTA/JTS, RMI, JDBC, Servlets, JSP, SAX/DOM, Web Services, SOAP, WSDL, UDDI, JAXB, JavaMail, WAP, WML, HTML
  • Tomcat, Apache Xalan, Apache Xerces, Jserv, JRun, JBuilder, TogetherJ, Web Logic 5.x/6.x, Websphere 3.5/4

And chances are a Java based curriculum won't prepare you much better than a C++ based one would against a list like that.

share|improve this answer
1  
I'd add that (at least in my area) C++ jobs also pay quite a bit better than Java jobs (objective) and are generally more interesting (subjective). –  Cercerilla Nov 11 '10 at 22:29

I think a lot depends on your personality. At least from my perspective, Java and C++ have radically different orientations that appeal to substantially different kinds of people.

When you get down to it, Java is really mostly a big class library, with enough of a language to be able to instantiate objects and invoke methods from that library. "Learning Java" consists, in large part of memorizing (or at least becoming aware of) what's in the library and how it's organized, so you can find the things you want when you want them.

C++ places much less emphasis on providing pre-written code. While it does include a library (STL1), that library is less about the code that's included than it is about a style and set of principles. It's entirely possible to write code that's clearly and easily recognizable as "STL" code, even though it uses little or even none of the pre-written code at all.

There's also a fairly substantial difference in how the languages are used. Java has placed a heavy emphasis on keeping the language simple. This makes it easy to build tools that manipulate Java code in various ways (e.g., for refactoring). It also means that you tend to need tools that can do so, because refactoring often involves quite substantial changes to large amounts of code.

C++ is a much more complex language, which means (among other things) that building tools to manipulate C++ source code is tremendously more difficult than for Java. The balance to that is that it's much less necessary -- a refactoring job that might involve hundreds of changes to dozens of files in Java might be accomplished by (for example) changing a single template parameter in C++.

Java places a great deal more emphasis on being easy to learn. C++ places much more emphasis on being easy to use -- but (unfortunately) only if you really know what you're doing.

I'm not going to advocate for one or the other. My opinion of the languages is a lot less relevant than your having some idea of what to expect from each, and taking an honest look at yourself to figure out which is likely to suit you better.

1Yes, I know that's not really accurate, but I'm trying to keep this from turning into a book...

share|improve this answer

Having taught both C++ and Java at the college level, I would strongly recommend Java.

Java assists in the learning process, and encourages good programming behavior. The built-in libraries for Java are useful and easily available in every install. Being able to create a GUI app in one sentence, using the built-in libraries available in every Java install and that match all the tutorials the students find in a Google search, is crucial to helping students get beyond the language and start understand programming concepts.

The IDEs for Java provide support for both beginning and continuing students. Bringing powerful refactoring tools into the conversation early (while discussing OOP, for example) will help students learn to write maintainable code.

While C++ is a useful language to know, the additional concepts learned in C++ are not really worth the extra effort of the language as a whole. There are a large extra set of "gotchas" that must be taught around that can be introduced at a later time (memory management problems and buffer overflows to name a couple). Requiring students to understand these before moving on to concepts like algorithmic complexity and inheritance slows you down, the way requiring a driver to understand tire pressure before driving would slow down Driver's Ed. Sure, you need to know it. But you only need to know it as something that you'll get wrong some day, not as a building block of a larger concept.

share|improve this answer
2  
If you run into serious problems with buffer overflows and memory management, you're teaching C++ wrong. Which of the standard containers can overflow like a buffer? –  David Thornley Nov 4 '10 at 20:12
    
Arrays? I may, in fact, have been teaching C++ wrong; this was well over a decade ago. –  Alex Feinman Nov 5 '10 at 12:45

It's difficult because Java is undeniably easier to learn. You will be doing more sooner with Java.

C++ is a much more difficult language to work with. Pointers and memory management are conceptually and practically tricky to work with. C++ doesn't offer you any safety nets.

In the long term it would be useful to understand all the things that C++ teaches you. Also the transition from C++ to Java is far easier than the other direction.

But I do wonder whether when starting out and during a lot of degree projects the extra overhead and debugging you have to do in order to get something working in C++ would actually make your projects harder, your deadlines tougher to meet and your life far more frustrating. To achieve the same thing in C++ and Java I would say that in almost every case you would get the job done faster in Java and run into fewer annoying problems. That could be a really big deal when you are at the end of a semester and have five courses needing their end of course project on the same day.

The other side of that is that if those trials don't cause you to throw in the towel altogether, they will make you a better programmer if you have mastered C++. And if your career is with C# or Java or python and you never have to touch another pointer in your life, you will appreciate it a whole lot more...

share|improve this answer

C++ is the more flexible and offers a deeper of understanding. Unquestionably, you will gain more from C++ than from Java. C++ is also harder, because it's more complex.

That said, C++ jobs are not nearly as common as Java jobs.

Java and its descendant, C#, are the standard solutions for the enterprise/corporate big-iron coding space. I strongly recommend learning one of the two in your second year and being very comfortable with that one by the time you finish your degree. It will let you get jobs much easier. That does not mean I think those jobs have significant intellectual interest on average. I made a pass through craigslist software jobs in the Rocky Mountains recently and most of the jobs were C#/Java and related to what is termed "CRUD" software; IMO that's very boring.

share|improve this answer

I can't believe people are advocating C++ as a first language! You will spend most of your time writing boiler plate and trying to get around the limitations and fish hooks in the language than actually learning how to program.

Java is a much simpler language and won't get in the way of your learning.

If you must learn C++, learn the concepts with Java and then go to C++, or better still, OBJ-C if you want to write Mac software. Java and OBJ-C aren't too dissimilar.

FYI I have spent 10 years as a commercial C++ developer.

share|improve this answer
    
This won't be my first language. I'm a programmer now going back to school to actually get a degree. My experience with C++ and Java is limited, but I do have experience with C and Objective-C. But thanks for taking the time to answer. –  Philip Regan Nov 11 '10 at 23:38
3  
Java will get in the way of your learning. It will teach you total non-truths about language-independent concepts. –  DeadMG Mar 11 '12 at 16:26

Schools and scholars who advocate Java as the first choice should have their heads examined (or simply get a real job out there.) I'm saying this as a person who has done both application and system development in Java for the last 12 years. Java is an atrocious language for teaching.

The reason is the following: barring the gifted, most students can (and will most likely never) grasp object orientation without understanding modular programming. And they cannot understand modular programming without first understanding structured programming in a procedural language. Plain and simple. Testament of this (among other things) is that even though we have known OO for 3-4 decades now, people still write hyper-spaghetti in practice.

Furthermore, a person solely relying on a gc-based language (be it Java or .NET) can never really get close to the hardware. Unless your entire ambition is to make dynamic web pages, guess what? You need to be comfortable with getting close to the language.

You go to a CS school to become a well-rounded computer scientist and programmer (hopefully with quite a few credit hours of hands-on programming practice in many programming languages.) If you all you know is Java (or .NET or C or Python whatever) then you are a "Java programmer" (not a programmer that can work on Java, but a "Java programmer"). And that makes as much sense as saying you are a "hammer carpenter" or a "Phillip screw driver mechanic", doesn't it.

A good school will expose you to C (or some other procedural language like Pascal or Ada), then C++ and a assembly, leaving you to learn Java on your own as you pursue project capstone courses on your junior/senior year. Also, it should provide you with exposure to functional languages so that you understand the concept of passing computational blocks as arguments, side-effect free computations, location transparency and the like (which have real practical applications, even on the web.)

You need to know what a segfault is. You need to know what paging, virtual memory and all that crap mean. You need to know how to decompose problems in modules (be them procedural and OO-based). You need to know how OO systems are truly implemented under the hood (so that you know the cost.) You need to know where OO abstraction breaks (and they do because the world and complex problems are not necessarily object-oriented.)

You need to know all that stuff so that you become a well-rounded computer scientist capable of working either on the enterprise or at the very low level implementing system-level stuff, either for the commercial or the public sector, both large scale and small scale.

Academics who have been pushing for Java as the-one-and-only language to rule them all are completely clueless as to what the industry really need. Clueless. Unforgivable clueless. That's what happen when they work on ivory towers looking at the industry at a distance.

They have turned Computer Science departments into expensive 4-year vocational schools churning one-programming-language-trick ponies. And that could be forgivable if they could at least teach students basic business/enterprise/organizational skills (that is, abandon the CS facade and adopt a MIS curriculum.) But they don't even do that, which I think it's a great disservice to the industry, the economy and ultimately the students.

I would suggest you read Joel Spolsky' piece on "Java Schools".

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

In summary, if they don't teach you a procedural programming language (be it an industrial one like C or Ada or one good enough for teaching like Pascal), and they give you if C++ (if you are lucky) or Java/C# (if you are unlucky), I would look for another school. Plain and simple, from a guy who has been using Java for a living in the real world for quite a while.

share|improve this answer
    
From someone who knows Java, C and C++ pretty well and who didn't graduate too long ago, I'm going to have to disagree. C (or C++) VS Java - Java is way 'easier'. Maybe if I started with C++ (which I think is pretty awesome (but not easy) btw) (instead of (Delphi (eww) +) Java) it's entirely possible that I would've gotten demotivated, given up and not become a programmer (though maybe we just had a bad C++ teacher). But yes, learning C++ to understand the internals of Java was absolutely invaluable. And I'd guess about 95% of programmers these days "never really get close to the hardware". –  Dukeling May 13 '13 at 12:27
    
"C (or C++) VS Java - Java is way 'easier'" - well, that is a well-known given. I'm not sure what that has to do with my post, though (?????) –  luis.espinal May 13 '13 at 19:18
    
Easier to understand, easier to teach, easier to learn, thus I disagree that "Java is an atrocious language for teaching" and that you should learn C first (maybe an easier procedural language is fine). I'm also saying C or C++ is good to know, but not to start with, because in this case you're likely to scare away all but the most hardcore programmers, because I'm sure that's all who will survive an introduction to programming via C++. Not that I mind a world of hardcore programmers, but other people might. Yes, you are saying be well-rounded, but I say lead with Java or similar. –  Dukeling May 13 '13 at 21:22
    
Easier to understand and teach does not necessarily translate to being an adequate language for pedagogical purposes. After 12 years of working with Java, I'm convinced of this. A much better pedagogical language that is easier than C or C++ would be Python, for instance ... or any language that does not force every method to be in a class, that is, a language that is truly multi-paradigm as opposed to Java where everything is "supposedly" an object, where there are no good alternatives to scoping beyond classes and packages, and so on and so on. It limits the ability to teach proper modeling. –  luis.espinal May 15 '13 at 23:17
    
Java, by forcing you to learn programming in a noun-oriented, everything-as-object mode, it provides poor modeling metaphores for other paradigms that are more suitable for actual world modeling. A professional developer from the trenches can work around that limitation. Students do not, and forgive me, but very few college professors have from-the-trenches experience to know the distinction. I would pick Python or Ruby (or actually Lisp or BASIC) over Java if C/C++ is too hardcore. –  luis.espinal May 15 '13 at 23:20

protected by ChrisF May 13 '13 at 12:51

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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