If you had a choice, which would it be: C++ or Java?
Hey Hackers, here is my quandary. I have to make a choice between C++ and Java as the next language I learn at school. If you were me, which would you select? Why?
My career interests are mainly in data analysis, with perhaps some financial applications later on. Which of these two languages would give me the most traction?
28 comments
[ 2.7 ms ] story [ 57.1 ms ] threadSeriously: of those 2 choices, I would tend towards C (more than C++). I would prefer more choice, of course. Current Lisp compilers are very efficient.
Big users of C++ are more tech-oriented. These are the people that would use something better but they need the 2x speedup, because it's a major competitive advantage in a mature pure tech firm.
example: google.com
Big users of Java are more enterprise-oriented. They use it because it is proven, and they can hire programmers for it, and they can manage big projects with it.
example: SAP.com
IMO: chase the $$$, learn Java. But if you work hard you can learn the basics fast, and keep learning other languages. Once you know many languages and the paradigms behind them, any given language is just a point in "language space" and the details of the language are obvious, because they couldn't be any other way.
They've even release a large amount of libraries developed internally here: http://code.google.com/p/guava-libraries/
If I said that ultimately I wanted to use either language for distributed computing applications, which then?
But, I just find that Java makes life easier. For example, you don't have to worry about endianess issues. You don't have to worry about portability (as long as you can run a JVM). You can serialize objects across the network easily, and if you want to do stuff like RPC, there's Cajo.
On the C++ side, you have stuff like LAPACK? Though I'm not too sure about this stuff...
Also, Google's Protocol Buffers project is quite helpful in passing data around. (C++, Java, Python, in any combination)
Our developers use Java (mostly).
Our research department uses whatever they are most comfortable with for research, but the result of their research is coded up in C++. If we had to do it over, we'd probably do everything in Java. Misc. notes:
Personally, I am WAY more productive in Java.
I supplement Java with Clojure.
I find the performance penalty for using Java is pretty-much negligible. It's always how you do it that matters more than what language you do it in. Don't use Java Generics for number crunching though... use a dedicated primitives collection library like Colt.
Java and C++ are quite similar in some respects. I would say though, that it's easier to go from C++ to Java, than from Java to C++.
Best C++ books:
Accelerated C++ by Andrew Koenig and Barbara E. Moo
Effective C++ by Scott Meyers (make sure you get the 3rd edition)
Best Java books:
Effective Java by Joshua Bloch
Java Concurrency in Practice by Brian Goetz, Tim Peierls, Joshua Bloch, and Joseph Bowbeer
If you have to use C++, start using the Boost C++ libraries early on. You can learn a great deal just by using the Boost libraries, and reading their documentation.
How about IDEs for each?
Eclipse for Java.
Visual Studio for C++ on Windows. Netbeans everywhere else?
I am constantly dissapointed with my tools.
(edit) ViEmu for Visual Studio is excellent. I'm not sure if it's Eclipse or viPlugin for Eclipse, but one of them is laggy.
(edit) In all honesty, skennedy makes a very good point. C# does seem to be gaining popularity. (And yes I'm aware of the Mono project.) Frankly, I just don't trust Microsoft. There have been compatibility issues with migrating between early versions of the .NET framework, and the end of Visual Basic left a bad taste in many mouths.
Maybe it depends on your specific needs, but I am not sure why you would want any products you develop (regardless of the programming language) to share server resources with the Oracle database. My teams always separate the product load across servers and tiers. If you can afford the $20,000 per processor for Oracle, hopefully, you have multiple tiers to put your code elsewhere.
If you don't know Python, learn it. Then learn plain C, then perhaps Java, and only C++ after at least those 3.
Also, a lot of C++ "good practice" are "built in" in Java. For instance, you won't have to use #ifndef #endif or to declare your function in a header file. So, again, I think Java is a better choice since, if you have to learn and use C++, you will already know the good practices.
C++ is closer to the machine. You'll have to worry about things like memory management, pointers, sigfaults, etc - a great learning experience.
After this you should be able to pick up Java no problem. Although if you want to be really productive or hate typing, Id pick Python.