If you had a choice, which would it be: C++ or Java?

4 points by big_data ↗ HN
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 ] thread
Between C++ and Java? I would open a restaurant!

Seriously: 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.

My POV (I don't have any special insight):

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.

At some point, this does become an economic decision. Java does seem to offer the most in terms of use on the job. C++ is really strong in certain verticals like finance.
I am seriously bummed by my lack of choices. As always though, I want to make the best of it.

If I said that ultimately I wanted to use either language for distributed computing applications, which then?

For distributed computing: Java.
Any examples come to mind?
Well, maybe I'm not the best person to ask, and my answer was a bit off-the-cuff. The best answer is probably more like: it depends on what you're doing.

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)

Distributed computing in Java? Use Erlang instead...
I happen to work for a company in the financial sector.

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.

Thanks for the book tips! These will help after I make my choice.

How about IDEs for each?

Oh man.... the tooling situation....

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.

I was poking at Bloodshed Dev-C++ to test it out. Seems pretty good. Any experience with it?
Never user Java without Eclipse. You will be much productive in Java using Eclipse.
In addition to the point about chasing the $$$ by learning Java, I would definitely call your attention to C#. C# is based on C++, starting to pick up speed (think Sharepoint), and developers are coveted right now for the small but growing market.
How easy is it to use C# on a (shudder) Oracle Solaris box?

(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.

C# would put me in the money if I go .NET after school. But is it used enough in applications similar to Java in Hadoop to make it worth learning?
If you are using C#, you are using a Windows box. But you can tie into Oracle using the ODBC connection.

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.

I simply meant that Solaris is now an Oracle property - not that they're Oracle DB boxes.
Ack. Still trying to get used to replacing all mentions of "Sun" with "Oracle". Sorry for the misunderstanding.
C++ is really an expert's language. It should be something you learn after several other languages.

If you don't know Python, learn it. Then learn plain C, then perhaps Java, and only C++ after at least those 3.

I disagree. It was talk like this that convinced me to learn a couple of other languages when I was a kid before jumping in to C++, and I regret not going straight for it. C++ is not difficult to learn, but once you have it down you'll have a better understanding and appreciation of all the higher level languages that abstract the hard stuff away for you but sometimes perform like crud.
(comment deleted)
If you want to do quant finance as a career. Learn C++. It is the industry standard for quant work.
I think Java will help you focus on more high level stuff than C++, which is a good thing. For instance, you will spend less time debugging subtile C++ corner cases.

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.

(comment deleted)
(comment deleted)
Since you trying to learn something as apposed to just get something done, go for C/C++.

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.